Tomcat设置JNDI 资源

 Web应用描述符文件(/WEB-INF/web.xml)可以用于设置资源的创建和引用。

设置时用到的元素有三个:

l        <env-entry>

l        <resource-ref>

l        <resource-env-ref>

如果Tomcat不能识别适当的资源工厂,或者还需要设置其他信息。必须在Tomcat创建资源前设置必要的信息,这些信息一般是在$CATALINA_BASE/conf/server.xml文件中设置的,最好是在每个Web应用的上下文设置文件(META-INF/context.xml)中设置。设置时用到的元素有:

l        <Environment>

l        <Resource>

l        <ResourceLink>

l        <Transaction>

context.xml中定义的资源,没有必要在web.xml中定义。建议保留在web.xml中的定义是为了说明web应用对资源的要求。

如果在context.xmlweb.xml中定义了相同名称的资源,只有在context.xml中设置了override属性为trueweb.xml中的设置就可以优先。

全局设置

$CATALINA_BASE/conf/server.xml中的元素<GlobalNamingResources>是对服务器的全局资源的设置。在Web应用的context.xml中用<ResourceLink>可以包含这些资源。这样的资源,也没有必要在web.xml中定义,建议保留在web.xml中的定义是为了说明web应用对资源的要求。

web.xml文件示例:

<resource-ref>
  <description>
    Resource reference to a factory for java.sql.Connection
    instances that may be used for talking to a particular
    database that is configured in the <Context>
    configurartion for the web application.
  </description>
  <res-ref-name>
    jdbc/EmployeeDB
  </res-ref-name>
  <res-type>
    javax.sql.DataSource
  </res-type>
  <res-auth>
    Container
  </res-auth>
</resource-ref>

 

 

context.xml文件示例:

<Context ...>
  ...
  <Resource name="jdbc/EmployeeDB"
            auth="Container"
            type="javax.sql.DataSource"
            username="dbusername"
            password="dbpassword"
            driverClassName="org.hsql.jdbcDriver"
            url="jdbc:HypersonicSQL:database"
            maxActive="8"
            maxIdle="4"/>
  ...
</Context>
 
 
详见:http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值