1.使用org.springframework.jdbc.datasource.DriverManagerDataSource
说明:DriverManagerDataSource建立连接是只要有连接就新建一个connection,根本没有连接池的作用。
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>${jdbc.driverClassName}</value> </property>
<property name="url"><value>${jdbc.url}</value> </property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password"><value>${jdbc.password}</value></property>
</bean>
2.使用dbcp、proxool、c3p0等数据库连接池
说明:这是一种推荐说明的数据源配置方式,它真正使用了连接池技术
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property>
<property name="url"><value>jdbc:oracle:thin:@localhost:1521:orcl</value></property>
<property name="username"><value>test</value></property>
<property name="password"><value>test</value></property>
<property name="maxActive"><value>255</value></property>
<property name="maxIdle"><value>2</value></property>
<property name="maxWait"><value>120000</value>
</property>
</bean>
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="alias" value="proxoolDataSource"/>
<property name="driver" value="${connection.driver_class}" />
<property name="driverUrl" value="${connection.url}" />
<property name="user" value="${connection.username}" />
<property name="password" value="${connection.password}" />
<property name="maximumConnectionCount" value="${proxool.maximum.connection.count}"/>
<property name="minimumConnectionCount" value="${proxool.minimum.connection.count}" />
<property name="statistics" value="${proxool.statistics}" />
<property name="simultaneousBuildThrottle" value="${proxool.simultaneous.build.throttle}"/>
</bean>
3.使用org.springframework.jndi.JndiObjectFactoryBean
说明:JndiObjectFactoryBean 能够通过JNDI获取DataSource
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/roseindiaDB_local</value>
</property>
</bean>