tomcat - 在 Tomcat for Oracle 中使用 JNDI 的分步指南

标签 tomcat jndi

我有一个现有的基于 spring 框架的 Web 应用程序。我想在 Tomcat 6 和 Oracle 服务器上使用 JNDI。请解释一个简单的分步过程。

最佳答案

请按照以下步骤操作:

  1. 在标签<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"/>

  1. 在标签<Context>中添加以下代码在以下文件中

apache-tomcat-6.0.37/conf/context.xml

<ResourceLink name="jdbc/dbName" global="jdbc/dbName" type="javax.sql.DataSource"/>

  1. 在文件中添加如下代码

applicationContext.xml

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/dbName" expected-type="javax.sql.DataSource" />

  1. 确保 <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

  1. 确保

ojdbc14.jar

存在于文件夹中:

apache-tomcat-6.0.37\lib


  1. 删除应用程序中定义的先前数据库连接参数(applicationContext.xml 中定义的属性文件/dataSource bean)。

这应该足够了。

关于tomcat - 在 Tomcat for Oracle 中使用 JNDI 的分步指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26219550/

相关文章:

java - 在 Tomcat Grails 中禁用缓存

Spring 测试框架 - JNDI 资源

javax.命名.NameNotFoundException : Name ejb/com not found in context "java:comp/env"

java - SearchControls.setTimeLimit() 是否处理读取超时?

java - Spring-Boot > 使用 JNDI 设置 application.properties

java - 如果 DistinguishedName 有引号,则无法从组中获取成员

java - Java中有openID实现吗?

tomcat - 登录使用 ldap 验证的 openam 时验证失败

web-services - wsdl 2 java : deploy a web service with apache cxf

java.lang.IllegalArgumentException : Illegal pattern character 'e' in java webapp 异常