日期:2014-05-16 浏览次数:20504 次
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3309/demo" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean>
destroy-method="close"属性, 以便Spring容器关闭时,数据源能够正常关闭.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/WEB-INF/jdbc.properties</value> </list> </property> </bean> <!-- 数据源配置,使用应用内的DBCP数据库连接池 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- Connection Info --> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxActive" value="${jdbc.maxActive}" /> <property name="maxIdle" value="${jdbc.maxIdle}" /> <property name="maxWait" value="${jdbc.maxWait}" /> <property name="defaultAutoCommit" value="false" /> <property name="validationQuery" value="select 1" /> <property name="testOnBorrow" value="true" /> </bean>
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc\:mysql\://127.0.0.1/demo?zeroDateTimeBehavior\=convertToNull&characterEncoding\=utf-8 jdbc.username=root jdbc.password=root jdbc.maxActive=20 jdbc.maxIdle=10 jdbc.maxWait=4000