如何使用Tomcat提供的JNDI数据源?

如何使用Tomcat提供的JNDI数据源?,第1张

如何使用Tomcat提供的JNDI数据源?

如果使用基于Spring XML架构的配置,请在Spring上下文中进行如下设置

<beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">...<jee:jndi-lookup id="dbDataSource"   jndi-name="jdbc/DatabaseName"   expected-type="javax.sql.DataSource" />

或者,使用以下简单的bean配置进行设置:

<bean id="DatabaseName" >    <property name="jndiName" value="java:comp/env/jdbc/DatabaseName"/></bean>

你可以使用以下内容在tomcat的server.xml中声明JNDI资源

<GlobalNamingResources>    <Resource name="jdbc/DatabaseName"   auth="Container"   type="javax.sql.DataSource"   username="dbUser"   password="dbPassword"   url="jdbc:postgresql://localhost/dbname"   driverClassName="org.postgresql.Driver"   initialSize="20"   maxWaitMillis="15000"   maxTotal="75"   maxIdle="20"   maxAge="7200000"   testonBorrow="true"   validationQuery="select 1"   /></GlobalNamingResources>

并从Tomcat的web context.xml中引用JNDI资源,如下所示:

  <Resourcelink name="jdbc/DatabaseName"   global="jdbc/DatabaseName"   type="javax.sql.DataSource"/>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4901468.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存