by

Load properties from property file to spring.xml file

datasource.properties

datasource.driverClass=oracle.jdbc.driver.OracleDriver

datasource.jdbcUrl=jdbc:oracle:thin:@10.0.1.100:1521:xe
datasource.user=user
datasource.password=password
datasource.redis.address=127.0.0.1
datasource.redis.port=6379

c3p0.minPoolSize=5
c3p0.maxPoolSize=20	    
c3p0.acquireIncrement=1
c3p0.maxStatements=50
c3p0.idleConnectionTestPeriod=3000
c3p0.loginTimeout=300

spring.xml

<!-- load properties from property file -->
<context:property-placeholder location="classpath:datasource.properties" />

<!-- using properties from property file -->
  <bean id="myContactDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <!-- Connection properties -->
      <property name="driverClass" value="${datasource.driverClass}" />
      <property name="jdbcUrl" value="${datasource.jdbcUrl}" />
      <property name="user" value="${datasource.user}" />
      <property name="password" value="${datasource.password}" />
      
      <!-- Pool properties -->
      <property name="minPoolSize" value="${c3p0.minPoolSize}" />
      <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
      <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
      <property name="maxStatements" value="${c3p0.maxStatements}" />
      <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
      <property name="loginTimeout" value="${c3p0.loginTimeout}" />
  </bean>

Escreva um comentário

Comment