[英]Spring 2 JDBC datasource configuration
I am currently looking at an application that uses Spring and Spring JDBC. 我目前正在查看使用Spring和Spring JDBC的应用程序。
http://static.springsource.org/spring/docs/2.0.x/reference/jdbc.html http://static.springsource.org/spring/docs/2.0.x/reference/jdbc.html
I can't find from the doc ways / where to configure settings such as set pool size, re-connection, test on borrow. 我找不到doc方式/在哪里配置设置,如设置池大小,重新连接,借用测试。
Am i missing something here? 我错过了什么吗? I am new to Spring. 我是Spring的新手。 Is it that this plain vanilla JDBC option does not allow me to do what is described or is it that i would need something like c3po library? 难道这个简单的vanilla JDBC选项不允许我做所描述的内容,还是我需要像c3po库这样的东西?
These properties are not part of Spring but underlying DataSource
implementation. 这些属性不是Spring的一部分,而是基础DataSource
实现。 First you have to include some database pooling library like dbcp : 首先,您必须包含一些数据库池,如dbcp :
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
Once you added this library you configure the provided DataSource
implementation: 添加此库后,您可以配置提供的DataSource
实现:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="username" value="user" />
<property name="password" value="pwd" />
<property name="url" value="some:url" />
<property name="driverClassName" value="some.class.Driver" />
<property name="initialSize" value="5" />
<property name="maxActive" value="10" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="SELECT 1" />
</bean>
You can also choose different DataSource
implementations like c3p0 . 您还可以选择不同的DataSource
实现,如c3p0 。 Finally you can obtain DataSource
configured in your application server, eg using jndi . 最后,您可以获取在应用程序服务器中配置的DataSource
,例如使用jndi 。 Spring JDBC support uses any DataSource
implementation provided. Spring JDBC支持使用提供的任何DataSource
实现。 Also Spring ships with some very simple DriverManagerDataSource
intended for testing. Spring还提供了一些非常简单的DriverManagerDataSource
用于测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.