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



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

请按照以下步骤操作:

  1. 在以下文件的标记<GlobalNamingResources>中添加以下代码:

apache-toncat-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-toncat-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. 确保applicationContext.xml中的<beans:xmlns标签具有以下数据:

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-toncat-6.0.37\lib


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

这就足够了。

这是一门很好的知识,您还可以分享如何为外部LDAP数据源配置JNDI吗?

在遵循您的步骤之后,数据库JNDI对我来说很好。您可以在下面的链接中获得更多详细信息。使用Tomcat 的外部LDAP JNDI连接

谢谢Anny

最新更新