Tomcat 6.0 两个数据源, hibernate配置JNDI问题。
项目需要配置两个数据源,采用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>
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>
...全文
相关推荐
Tomcat6配置连接池
##### 2.6 启动Tomcat服务完成以上所有配置后,启动Tomcat服务即可验证连接池是否正确配置。#### 三、注意事项1. **兼容性问题**:确保使用的数据库驱动与Tomcat版本兼容。
c3p0连接池
**Tomcat配置** - **JNDI配置**:在Tomcat的`context.xml`中定义数据源,将c3p0数据源与JNDI绑定,方便多应用共享。
Struts2+Spring+Hibernate3.1图解配置教程
配置数据源,例如使用JNDI数据源或定义一个`DataSource` Bean。3.
apache-tomcat-7.0.86.zip
此外,Tomcat还支持JNDI(Java Naming and Directory Interface),使得应用可以通过名字查找并透明地使用数据源。
c3p0数据连接池
#### 兼容性c3p0 与多种主流数据库和应用服务器(如 Hibernate、JBoss、Oracle、Tomcat)都有良好的兼容性。


