jdbc.user=root
jdbc.password=root
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql:///spring
jdbc.initPoolSize=5
jdbc.maxPoolSize=10
<!-- 导入资源文件-->
<context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
<!--配置c3p0数据源-->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="initialPoolSize" value="${jdbc.initPoolSize}"></property>
<property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
</bean>
@Test
public void testDataSource() throws SQLException {
DataSource dataSource =ctx.getBean(DataSource.class);
System.out.println(dataSource.getConnection());
}
原文:https://www.cnblogs.com/shaoyu/p/11671570.html