Spring 2 JDBC数据源配置 [英] Spring 2 JDBC datasource configuration
问题描述
我目前正在研究使用Spring和Spring JDBC的应用程序.
I am currently looking at an application that uses Spring and Spring JDBC.
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.
我在这里想念什么吗?我是Spring的新手.是这个普通的JDBC选项不允许我执行所描述的操作,还是需要c3po库之类的东西?
Am i missing something here? I am new to 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?
推荐答案
这些属性不是Spring的一部分,而是DataSource
实现的基础.首先,您必须包含一些数据库池库,例如 dbcp :
These properties are not part of Spring but underlying DataSource
implementation. First you have to include some database pooling library like dbcp:
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
添加此库后,便配置提供的DataSource
实现:
Once you added this library you configure the provided DataSource
implementation:
<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>
您还可以选择其他DataSource
实施方式,例如 c3p0 .最后,您可以获得在应用程序服务器中配置的DataSource
,例如使用 jndi 的问题. Spring JDBC支持使用提供的任何DataSource
实现. Spring还附带了一些非常简单的 DriverManagerDataSource
用于测试.
You can also choose different DataSource
implementations like c3p0. Finally you can obtain DataSource
configured in your application server, e.g. using jndi. Spring JDBC support uses any DataSource
implementation provided. Also Spring ships with some very simple DriverManagerDataSource
intended for testing.
这篇关于Spring 2 JDBC数据源配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!