tomcat配置jndi資料來源
在tomcat中加全域性資料庫連線
server.xml檔案修改 ,在<GlobalNamingResources>節點加下面紅色字型的配置
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
<!-- 注意jdbc/oracleCaodegao
<Resource acquireIncrement="2" acquireRetryAttempts="30" acquireRetryDelay="1000" auth="Container" breakAfterAcquireFailure="false" driverClass="oracle.jdbc.driver.OracleDriver" factory="org.apache.naming.factory.BeanFactory" idleConnectionTestPeriod="60" initialPoolSize="20" jdbcUrl="jdbc:oracle:thin:@伺服器IP:1521:xe" maxIdleTime="7200" maxPoolSize="50" maxStatements="0" minPoolSize="20" name="jdbc/oracleCaodegao" password="密碼" testConnectionOnCheckin="false" testConnectionOnCheckout="false" type="com.mchange.v2.c3p0.ComboPooledDataSource" user="使用者名稱"/>
</GlobalNamingResources>
context.xml這裡加個配置
<!-- 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" />
-->
<ResourceLink name="jdbc/oracleCaodegao" global="jdbc/oracleCaodegao" type="javax.sql.DataSource"/>
</Context>
最後一步,Spring資料來源配置 改成下面的
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/oracleCaodegao" />
</bean>
以前的這些就不用了,註釋掉
<!--
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true" />
<property name="checkoutTimeout"
value="${cpool.checkoutTimeout}" />
<property name="initialPoolSize" value="${cpool.minPoolSize}" />
<property name="minPoolSize" value="${cpool.minPoolSize}" />
<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
<property name="acquireIncrement"
value="${cpool.acquireIncrement}" />
<property name="maxIdleTimeExcessConnections"
value="${cpool.maxIdleTimeExcessConnections}" />
</bean>
-->