spring 配置文件中dbcp连接池,jdbc连接池 引入 配置文件properties,但是不能用$符号引用里面的变量问题
第一种配置 jdbc连接池
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" <span style="color:#ff0000;">default-lazy-init="true"</span>> <span style="color:#ff0000;"><context:property-placeholder ignore-resource-not-found="false" ignore-unresolvable="true" location="classpath:/application.properties" /></span> <!-- Tomcat JDBC连接池 --> <span style="color:#ff0000;"><bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"></span> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="defaultAutoCommit" value="false" /> <property name="maxActive" value="${jdbc.pool.maxActive}" /> <property name="maxIdle" value="${jdbc.pool.maxIdle}" /> <property name="minIdle" value="${jdbc.pool.initialSize}" /> <property name="initialSize" value="${jdbc.pool.initialSize}"/> <property name="testWhileIdle"><value>true</value></property> <property name="validationQuery"><value>SELECT 1</value></property> <property name="validationQueryTimeout" value="10"/> <property name="validationInterval" value="30000"/> </bean> </beans>
jdbc连接池的 application.properties配置
#mysql database setting dev jdbc.dbtype=mysql jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1/aaa?useUnicode=true&characterEncoding=utf-8 jdbc.username=aaa jdbc.password=aaa jdbc.pool.maxIdle=100 jdbc.pool.maxActive=200 jdbc.pool.minIdle=50 jdbc.pool.initialSize=100
第二种配置 使用dbcp连接池
html] <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> </list> </property> <property name="fileEncoding" value="utf-8"/> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- 加载驱动 --> <property name="driverClassName" value="${driverClassName}"></property> <!-- 数据库的名字 --> <property name="url" value="${jdbc_url}"></property> <!-- 用户名密码 --> <property name="username" value="${jdbc_username}"></property> <property name="password" value="${jdbc_password}"></property> <!-- 最大连接数 --> <property name="maxActive" value="${jdbc_maxActive}"></property> <!-- 最大可空闲 --> <property name="maxIdle" value="${jdbc_maxIdle}"></property> <!-- 最大等待秒数,单位为毫秒, 超过时间会报出错误信息 --> <property name="maxWait" value="${jdbc_maxWait}"></property> <!-- 默认自动提交,跟事务有关系,true,每执行就会提交,所以没有事务 --> <property name="defaultAutoCommit" value="${jdbc_defaultAutoCommit}"></property> </bean>
application.properties配置
[html] hibernate.dialect=org.hibernate.dialect.OracleDialect driverClassName=oracle.jdbc.driver.OracleDriver validationQuery=SELECT 1 FROM DUAL jdbc_url=jdbc\:oracle\:thin\:@211.67.188.189\:1521\:orcl jdbc_username=jd jdbc_password=admin jdbc_maxActive=100000 jdbc_maxIdle=0 jdbc_maxWait=1000 jdbc_defaultAutoCommit=false
转载自:http://blog.csdn.net/u013378306/article/details/50805714