xml配置文件中配置如下:
<spring:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="locations">
<spring:list>
<spring:value>classpath:conf/jdbc.properties</spring:value>
</spring:list>
</spring:property>
</spring:bean>
<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<spring:property name="driverClassName"
value="${jdbc.driverClassName}" />
<spring:property name="url"
value="${jdbc.url}" />
<spring:property name="username" value="${jdbc.username}" />
<spring:property name="password" value="${jdbc.password}" />
<spring:property name="maxActive" value="30" />
<spring:property name="maxIdle" value="10" />
<spring:property name="maxWait" value="1000" />
<spring:property name="defaultAutoCommit" value="true" />
</spring:bean>
jdbc.properties配置文件中连接数据库配置:
#sqlserver数据源配置
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://192.168.1.60:1408;DatabaseName=test
jdbc.username=sa
jdbc.password=1
#mysql数据源配置
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.60:3306/test
jdbc.username=root
jdbc.password=root
#Oracle数据源配置
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@10.60.17.9:1521:orcl
jdbc.username=admin
jdbc.password=admin