Tomcat +jndi.properties

发布于 2024-11-09 04:49:41 字数 1223 浏览 0 评论 0原文

我在 Tomcat 中遇到 JNDI 问题: 没有 tomcat 我已经使用了 JNDI,如下所示:

  Context context = new InitialContext();   
  JVoiceXml jvxml = (JVoiceXml) context.lookup("JVoiceXml");

和 jndi.properties :

  java.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory
  java.naming.provider.url=rmi://localhost:1099
  java.naming.rmi.security.manager=true

现在我想在我的 Web 应用程序中使用此代码(与 Tomcat 一起部署),我已将代码更改为:

 Context context = new InitialContext();
 Context envCtx = (Context) context.lookup("java:comp/env");
 JVoiceXml jvxml = (JVoiceXml) envCtx.lookup("JVoiceXml");

在 web.xml 中:

<resource-env-ref>
  <resource-env-ref-name>
    JVoiceXml
  </resource-env-ref-name>
  <resource-env-ref-type>
    org.jvoicexml.JVoiceXml
  </resource-env-ref-type>
</resource-env-ref>

在 context.xml 中:

<Resource name="JVoiceXml" auth="Container"
            type="org.jvoicexml.JVoiceXml"
            factory="com.sun.jndi.rmi.registry.RegistryContextFactory"
            url="rmi://localhost:1099"/>

什么我错过了,因为在lookup()之后我的JVoiceXml为空

i have a problem with JNDI in Tomcat:
without tomcat I have used JNDI as following:

  Context context = new InitialContext();   
  JVoiceXml jvxml = (JVoiceXml) context.lookup("JVoiceXml");

And jndi.properties :

  java.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory
  java.naming.provider.url=rmi://localhost:1099
  java.naming.rmi.security.manager=true

Now I want to use this code in my Web Application(deployed with Tomcat), I have changed the code to:

 Context context = new InitialContext();
 Context envCtx = (Context) context.lookup("java:comp/env");
 JVoiceXml jvxml = (JVoiceXml) envCtx.lookup("JVoiceXml");

In web.xml:

<resource-env-ref>
  <resource-env-ref-name>
    JVoiceXml
  </resource-env-ref-name>
  <resource-env-ref-type>
    org.jvoicexml.JVoiceXml
  </resource-env-ref-type>
</resource-env-ref>

And in context.xml:

<Resource name="JVoiceXml" auth="Container"
            type="org.jvoicexml.JVoiceXml"
            factory="com.sun.jndi.rmi.registry.RegistryContextFactory"
            url="rmi://localhost:1099"/>

What I have missed, because after lookup() my JVoiceXml is null

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不咬妳我踢妳 2024-11-16 04:49:41

您的 Tomcat 代码与您在 Tomcat 之外编写的代码不同。在 Tomcat 案例中您所做的就是将 RMI 注册表上下文工厂命名为 JVoiceXML。这似乎没有意义:RMI 注册表与 XML 无关。我怀疑你在这里根本不需要 java:comp/env 的东西。假设您有一个 RMI 注册表在某处运行:只需使用 Naming.lookup() 查找它即可。如果您希望它充当 Tomcat 资源,则需要定义一个可以创建它的工厂。那需要是 javax.naming.spi.ObjectFactory 的实例(?)。这可能会在 java:comp/env 命名空间之外执行 Naming.lookup() 或 JNDI 查找。

Your Tomcat code is not equivalent to what you wrote outside Tomcat. All you've done in the Tomcat case is name an RMI Registry context factory as JVoiceXML. That doesn't seem to make sense: the RMI Registry has nothing to do with XML. I suspect you don't need the java:comp/env stuff at all here. Presumably you have an RMI Registry running somewhere: just look it up with Naming.lookup(). If you want it to act as a Tomcat Resource, you need to define a factory that can create it. That needs to be an instance of javax.naming.spi.ObjectFactory (?). That may in turn do a Naming.lookup(), or a JNDI lookup, outside the java:comp/env namespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文