我有一个现有的基于 spring 框架的 Web 应用程序。我想在 Tomcat 6 和 Oracle 服务器上使用 JNDI。请解释一个简单的分步过程。
最佳答案
请按照以下步骤操作:
- 在标签
<GlobalNamingResources>
中添加以下代码在以下文件中:
apache-tomcat-6.0.37/conf/server.xml
<Resource name="jdbc/dbName" auth="Container" type="javax.sql.DataSource"
username="xyz" password="abcd"
url="jdbc:url"
driverClassName="oracle.jdbc.driver.OracleDriver"
initialSize="5" maxWait="5000"
maxActive="120" maxIdle="5"
poolPreparedStatements="true"/>
- 在标签
<Context>
中添加以下代码在以下文件中
apache-tomcat-6.0.37/conf/context.xml
<ResourceLink name="jdbc/dbName" global="jdbc/dbName" type="javax.sql.DataSource"/>
- 在文件中添加如下代码
applicationContext.xml
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/dbName" expected-type="javax.sql.DataSource" />
- 确保
<beans:xmlns
applicationContext.xml
中的标签有以下数据:
xmlns:jee="http://www.springframework.org/schema/jee"
以及这些模式在它们的 xsi:schemaLocation
中:
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans
- 确保
ojdbc14.jar
存在于文件夹中:
apache-tomcat-6.0.37\lib
- 删除应用程序中定义的先前数据库连接参数(applicationContext.xml 中定义的属性文件/dataSource bean)。
这应该足够了。
关于tomcat - 在 Tomcat for Oracle 中使用 JNDI 的分步指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26219550/