【发布时间】:2014-10-06 15:26:55
【问题描述】:
我有一个现有的基于 Spring 框架的 Web 应用程序。我想在 Tomcat 6 和 Oracle 服务器上使用 JNDI。请解释一个简单的分步过程。
【问题讨论】:
-
+1 回答您的问题。但是,像 JBoss 和 WAS 这样的应用程序服务器为您提供了许多自定义功能,例如数据库连接池,这将真正让您的应用程序在重负载应用程序中表现良好。
我有一个现有的基于 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" />
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
ojdbc14.jar
存在于文件夹中:
apache-tomcat-6.0.37\lib
应该够了。
【讨论】:
这是一个很棒的知识, 您能否也分享一下如何为外部 LDAP 数据源配置 JNDI?
按照您的步骤操作后,数据库 JNDI 为我工作得很好。 您可以在下面的链接中获得更多详细信息。 External LDAP JNDI connectivity using Tomcat
谢谢 安妮
【讨论】: