配置Tomcat JNDI數據源

一、在tomcat容器中conf/context.xml中配置
 java

<?xml version='1.0' encoding='utf-8'?>

<!-- The contents of this file will be loaded for each web application -->
<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->
	<!--
	<Resource 
			driverClassName="oracle.jdbc.driver.OracleDriver"
			url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"
			auth="Container" 
			maxActive="20" 
			maxIdle="10" 
			maxWait="10000" 
			name="jndi/test1"
			type="javax.sql.DataSource"
			password="test" 
			username="test" />  
			-->  
	<!-- 使用阿里巴巴的DruidDataSource配置針對Oracle數據庫的JNDI數據源 -->  
			<Resource 
			name="jndi/test2"  
			factory="com.alibaba.druid.pool.DruidDataSourceFactory"  
			auth="Container"  
			type="javax.sql.DataSource"  
            driverClassName="com.mysql.jdbc.Driver" 			
			url="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&amp;characterEncoding=utf-8"
			password="test" 
			username="test" 
			initialSize="20"
			minIdle="2"
			maxActive="50" 
			maxWait="10000" 
			timeBetweenEvictionRunsMillis="60000"
			minEvictableIdleTimeMillis="300000"
			poolPreparedStatements="false"
			maxPoolPreparedStatementPerConnectionSize="20"
			removeabandoned="true" 
			removeabandonedtimeout="60" 
			logabandoned="false" 
			filters="stat"/>
</Context>

二、在spring的applicationContext.xml中配置(在spring中集成)mysql

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jndi/test2</value>
        </property>
    </bean>
相關文章
相關標籤/搜索