日期:2014-05-16  浏览次数:20416 次

tomcat数据库连接池配置备忘
配置全局数据库连接池:
conf/server.xml
<GlobalNamingResources>
   <Resource name="jdbc/abc"
   auth="Container"
   type="oracle.jdbc.pool.OracleDataSource"
   driverClassName="oracle.jdbc.driver.OracleDriver"
   factory="oracle.jdbc.pool.OracleDataSourceFactory"
   url="jdbc:oracle:thin:@localhost:1521:orcl"
   user="222"
   password="2222"
   maxActive="20"
   maxIdle="10"
   maxWait="-1" />
</GlobalNamingResources>

conf/context.xml
<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink global="jdbc/abc" name="jdbc/cde" type="javax.sql.DataSource"/>
</Context>

web.xml
<resource-ref>
    <description>DataSource Reference</description>
    <res-ref-name>jdbc/cde</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

spring配置文件
<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">	
	<jee:jndi-lookup id="dataSource" jndi-name="jdbc/cde" />
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean id="jdbcExtractor"
		class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"
		lazy-init="true">		
	</bean>	
</beans>