1 <!-- 分散配置 -->
 2     <context:property-placeholder location="classpath:jdbc.properties" />
 3 
 4     <!-- 数据源 -->
 5     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
 6         <property name="driverClass" value="${jdbc.driverclass}" />
 7         <property name="jdbcUrl" value="${jdbc.url}"></property>
 8         <property name="user" value="${jdbc.username}" />
 9         <property name="password" value="${jdbc.password}" />
10 
11         <property name="maxPoolSize" value="${c3p0.pool.size.max}" />
12         <property name="minPoolSize" value="${c3p0.pool.size.min}" />
13         <property name="initialPoolSize" value="${c3p0.pool.size.ini}" />
14         <property name="acquireIncrement" value="${c3p0.pool.size.increment}" />
15     </bean>

 

jdbc.properties

 1 jdbc.driverclass=com.mysql.jdbc.Driver
 2 jdbc.url=jdbc:mysql://localhost:3306/springmvcdb?characterEncoding=utf-8
 3 jdbc.username=root
 4 jdbc.password=root
 5 
 6 c3p0.pool.size.max=10
 7 c3p0.pool.size.min=2
 8 c3p0.pool.size.ini=3
 9 c3p0.pool.size.increment=2
10 
11 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
12 hibernate.show_sql=true

 

 

 1     <!-- 加载外部的properties文件(方式一),用于解析${}形式的变量。 
 2         如果需要加载多个properties文件,就写在一起,之间使用逗号隔开。
 3     <context:property-placeholder location="classpath:cn/yht/spring/k_placeholder/jdbc.properties"/>
 4     -->
 5 
 6     <!-- 加载外部的properties文件(方式二) 
 7     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 8         <property name="locations">
 9             <list>
10                 <value>classpath:cn/yht/spring/k_placeholder/jdbc.properties</value>
11             </list>
12         </property>
13     </bean>

 

 posted on 2016-06-28 16:08  Just_Do  阅读(4059)  评论(1编辑  收藏  举报