Tomcat 6.0 两个数据源, hibernate配置JNDI问题。
MR小陳 2012-04-26 02:41:10 项目需要配置两个数据源,采用JNDI方式,我在spring中已经配置成功一个数据源,但配置第二个数据源时出现bug . 各位帮忙看下,感激不尽。
tomcat 6.0 context.xml如下:
Java代码
1.<Resource name="jdbc/ora10"
2. type="javax.sql.DataSource"
3. driverClassName="oracle.jdbc.driver.OracleDriver"
4. url="jdbc:oracle:thin:@10.10.26.69:1521:ora10g"
5. username="guoyuan" password="1qaz2wsx" maxActive="200" maxIdle="10"
6. maxWait="-1"
7./>
8.
9.<Resource name="jdbc/herora10"
10. type="javax.sql.DataSource"
11. driverClassName="oracle.jdbc.driver.OracleDriver"
12. url="jdbc:oracle:thin:@10.10.26.69:1521:ora10g"
13. username="guoyuan" password="1qaz2wsx" maxActive="200" maxIdle="10"
14. maxWait="-1"
15./>
<Resource name="jdbc/ora10"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@10.10.26.69:1521:ora10g"
username="guoyuan" password="1qaz2wsx" maxActive="200" maxIdle="10"
maxWait="-1"
/>
<Resource name="jdbc/herora10"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@10.10.26.69:1521:ora10g"
username="guoyuan" password="1qaz2wsx" maxActive="200" maxIdle="10"
maxWait="-1"
/>
web项目web.xml如下:
Java代码
1. <!-- jndi configration (hibernate.properties )-->
2. <resource-ref>
3. <description>DB DataSource</description>
4. <res-ref-name>jdbc/ora10</res-ref-name>
5. <res-type>javax.sql.DataSource</res-type>
6. <res-auth>Container</res-auth>
7.</resource-ref>
8. <!-- jndi configration (hibernate.properties )-->
9. <resource-ref>
10. <description>DB DataSource</description>
11. <res-ref-name>jdbc/herora10</res-ref-name>
12. <res-type>javax.sql.DataSource</res-type>
13. <res-auth>Container</res-auth>
14.</resource-ref>
<!-- jndi configration (hibernate.properties )-->
<resource-ref>
<description>DB DataSource</description>
<res-ref-name>jdbc/ora10</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<!-- jndi configration (hibernate.properties )-->
<resource-ref>
<description>DB DataSource</description>
<res-ref-name>jdbc/herora10</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
第一成功数据源spring配置文件下,如下:
Java代码
1.<!-- jndi datasource -->
2.<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
3. <property name="jndiName">
4. <value>java:comp/env/jdbc/ora10</value>
5. </property>
6.</bean>
<!-- jndi datasource -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/ora10</value>
</property>
</bean>