Tomcat6 JNDI配置
-
修改%TOMCAT_HOME%\conf\server.xml如下,在<GlobalNamingResources>中添加<Resource>
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/PmsGlobal" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
username="sa" password="sa" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://localhost:1042/pms" />
<Resource name="jdbc/CarGlobal" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
username="sa" password="sa" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://localhost:1042/car" />
</GlobalNamingResources>
?
-
修改%TOMCAT_HOME%\conf\context.xml如下,在<Context>中添加<ResourceLink>
<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/pms" global="jdbc/PmsGlobal" type="javax.sql.DataSource" />
<ResourceLink name="jdbc/car" global="jdbc/CarGlobal" type="javax.sql.DataSource" />
</Context>
-
?在项目的配置datasource的文件中做如下配置
<bean name="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/pms</value>
</property>
</bean>
<bean name="externalSysDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/car</value>
</property>
</bean>