【问题标题】:Step by step guide for using JNDI in Tomcat for Oracle在 Tomcat for Oracle 中使用 JNDI 的分步指南
【发布时间】:2014-10-06 15:26:55
【问题描述】:

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

【问题讨论】:

  • +1 回答您的问题。但是,像 JBoss 和 WAS 这样的应用程序服务器为您提供了许多自定义功能,例如数据库连接池,这将真正让您的应用程序在重负载应用程序中表现良好。

标签: tomcat jndi


【解决方案1】:

请按以下步骤操作:

  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. 在以下文件的标签&lt;Context&gt;中添加如下代码

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. 确保applicationContext.xml中的&lt;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-tomcat-6.0.37\lib


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

应该够了。

【讨论】:

  • 这个 applicationContext.xml 文件在哪里?
【解决方案2】:

这是一个很棒的知识, 您能否也分享一下如何为外部 LDAP 数据源配置 JNDI?

按照您的步骤操作后,数据库 JNDI 为我工作得很好。 您可以在下面的链接中获得更多详细信息。 External LDAP JNDI connectivity using Tomcat

谢谢 安妮

【讨论】:

  • 对不起,我不知道 LDAP 配置。不过我会试着找出答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-28
  • 2012-02-15
  • 2013-05-07
  • 1970-01-01
  • 2015-08-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多