在Spring/Tomcat中,jndi查找指的是哪个配置文件?: [英] In Spring/Tomcat, which configuration file do jndi lookups refer to?:

查看:66
本文介绍了在Spring/Tomcat中,jndi查找指的是哪个配置文件?:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让Spring/Tomcat应用程序解析一个变量,该变量在应用程序上下文中显示为JndiFactoryObjectName bean的属性.这是相关的bean条目:

I'm having trouble getting a Spring/Tomcat app to resolve a variable which appears as a property of a JndiFactoryObjectName bean in the application context. Here's the relevant bean entry:

当我尝试在服务器上运行它时,出现此错误:

When I try to run it on the server, it comes up with this error:

Caused by: javax.naming.NameNotFoundException: Name search.url is not bound in this Context

server.xml中的此项似乎无济于事:

This entry in server.xml doesn't seem to help:

(从Eclipse/STS中可以看到)

There's also an entry in (as seen from Eclipse/STS)

Tomcat v6.0 Server at localhost
   Catalina
     localhost
         ROOT.xml

<Context path="" reloadable="true" docBase="C:/myworkspace32/myAppName/WebContent">
        <ResourceLink global="search.url" name="search.url" type="java.lang.String"/>
</Context>

但是,这似乎没有影响.

However, this seem to have no impact.

推荐答案

以下是从tomcat访问JNDI资源的步骤

Here are the steps to access JNDI resource from tomcat

  1. 在server.xml中创建jndi资源

  1. Create jndi resource in server.xml

<Resource global="search.url" name="search.url" type="java.lang.String" />

  • 在context.xml中创建链接,以便所有Web应用程序都可以访问它.

  • Create the link in context.xml so that its accessible by all the web application.

    <ResourceLink name="search.url"  global="search.url" auth="Container" type="java.lang.String" />
    

  • 使用spring bean或jee标签注入jndi

  • Use spring bean or jee tag to inject the jndi

    <bean id="searchUrl" class="org.springframework.jndi.JndiObjectFactoryBean">
     <property name="jndiName" value="java:comp/env/search.url"/>
    </bean>
    

    可以避免使用jee contatiner标签指定环境,如下所示

    you can avoid specify the environment by using jee contatiner tag as follows

     <jee:jndi-lookup id="searchUrl" jndi-name="search.url" expected-type="java.lang.String" />
    

  • 这篇关于在Spring/Tomcat中,jndi查找指的是哪个配置文件?:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆