当前位置: 首页 > 知识库问答 >
问题:

jetty:如何声明JVM范围的jndi条目并绑定到java:comp/env

牛景同
2023-03-14

我试图在Jetty服务器中定义一些JNDI条目(它们将在JVM范围内),但它们并没有像预期的那样自动绑定到“java:comp/env”名称空间。我正在以下网址查看文档:http://wiki.eclipse.org/Jetty/Feature/JNDI#Configuring_env-参赛作品

这是我的jetty.xml:

<Configure id="server" class="org.eclipse.jetty.server.Server">

<New class="org.eclipse.jetty.plus.jndi.EnvEntry">
    <Arg></Arg>
    <Arg>prop/someValue</Arg>
    <Arg type="java.lang.String">hello</Arg>
    <Arg type="boolean">true</Arg>
</New>

</Configure>

正如Jetty示例所示,我原本以为它会绑定到“java:comp/env/prop/someValue”,但“java:comp/env”似乎根本没有被创建。

然而,查找“prop/someValue”确实有效。

注意-我没有一个webapp,所以没有WEB-INF/jetty-env.xml也没有web.xml.我只是启动一个Jetty服务器,并试图配置所需的JNDI条目。

还尝试使用“bindToENC”方法将我的条目显式绑定到:

<Configure id="server" class="org.eclipse.jetty.server.Server">

<New class="org.eclipse.jetty.plus.jndi.EnvEntry">
    <Arg></Arg>
    <Arg>prop/someValue</Arg>
    <Arg type="java.lang.String">hello</Arg>
    <Arg type="boolean">true</Arg>
</New>
    <Call name="bindToENC">
        <Arg>prop/someValue</Arg>
    </Call>

</Configure>

但这会导致服务器启动失败:

2012-11-14 11:17:25,648 DEBUG - XML new class org.eclipse.jetty.plus.jndi.EnvEntry (org.eclipse.jetty.xml.XmlConfiguration)
2012-11-14 11:17:25,650 DEBUG - SAVE prop/someValue in null (jndi)
2012-11-14 11:17:25,656 DEBUG - InitialContextFactory.getInitialContext() (jndi)
2012-11-14 11:17:25,664 DEBUG - Created initial context delegate for local namespace:org.eclipse.jetty.jndi.local.localContextRoot@664883c (jndi)
2012-11-14 11:17:25,665 DEBUG - InitialContextFactory.getInitialContext() (jndi)
2012-11-14 11:17:25,665 DEBUG - Created initial context delegate for local namespace:org.eclipse.jetty.jndi.local.localContextRoot@6e811c88 (jndi)
2012-11-14 11:17:25,666 DEBUG - Looking up name="__" (jndi)
2012-11-14 11:17:25,666 DEBUG - Adding binding with key=__ obj=org.eclipse.jetty.jndi.NamingContext@39dd3812 for context=null as __: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@39dd3812 (jndi)
2012-11-14 11:17:25,666 DEBUG - Subcontext __ created (jndi)
2012-11-14 11:17:25,666 DEBUG - Looking up name="prop" (jndi)
2012-11-14 11:17:25,666 DEBUG - Adding binding with key=prop obj=org.eclipse.jetty.jndi.NamingContext@6a8c436b for context=__ as prop: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@6a8c436b (jndi)
2012-11-14 11:17:25,666 DEBUG - Subcontext prop created (jndi)
2012-11-14 11:17:25,667 DEBUG - Removing binding with key=someValue (jndi)
2012-11-14 11:17:25,667 DEBUG - Adding binding with key=someValue obj=prop/someValue for context=prop as someValue: org.eclipse.jetty.plus.jndi.EnvEntry:prop/someValue (jndi)
2012-11-14 11:17:25,667 DEBUG - Bound object to someValue (jndi)
2012-11-14 11:17:25,667 DEBUG - Looking up name="prop" (jndi)
2012-11-14 11:17:25,667 DEBUG - Adding binding with key=prop obj=org.eclipse.jetty.jndi.NamingContext@27b15692 for context=null as prop: org.eclipse.jetty.jndi.NamingContext:org.eclipse.jetty.jndi.NamingContext@27b15692 (jndi)
2012-11-14 11:17:25,667 DEBUG - Subcontext prop created (jndi)
2012-11-14 11:17:25,667 DEBUG - Removing binding with key=someValue (jndi)
2012-11-14 11:17:25,668 DEBUG - Adding binding with key=someValue obj=hello for context=prop as someValue: java.lang.String:hello (jndi)
2012-11-14 11:17:25,668 DEBUG - Bound object to someValue (jndi)
2012-11-14 11:17:25,668 DEBUG - XML call bindToENC (org.eclipse.jetty.xml.XmlConfiguration)
2012-11-14 11:17:25,668 DEBUG - InitialContextFactory.getInitialContext() (jndi)
2012-11-14 11:17:25,668 DEBUG - Created initial context delegate for local namespace:org.eclipse.jetty.jndi.local.localContextRoot@6baa9f99 (jndi)
2012-11-14 11:17:25,671 DEBUG - >>> new root context requested  (org.eclipse.jetty.jndi.java.javaURLContextFactory)
2012-11-14 11:17:25,673 DEBUG - Adding binding with key=comp obj=Reference Class Name: javax.naming.Context
Type: parser
Content: org.eclipse.jetty.jndi.java.javaNameParser
 for context=null as comp: javax.naming.Reference:Reference Class Name: javax.naming.Context
Type: parser
Content: org.eclipse.jetty.jndi.java.javaNameParser
 (jndi)
2012-11-14 11:17:25,673 DEBUG - Looking up name="comp/env" (jndi)
2012-11-14 11:17:25,690 DEBUG - Using thread context classloader (jndi)
2012-11-14 11:17:25,690 DEBUG - No entry for classloader: sun.misc.Launcher$AppClassLoader@35a16869 (jndi)
2012-11-14 11:17:25,690 DEBUG - Looking up name="env" (jndi)
2012-11-14 11:17:25,690 WARN  - Config error at <Call name="bindToENC"><Arg>prop/someValue</Arg></Call> (org.eclipse.jetty.xml.XmlConfiguration)
2012-11-14 11:17:25,690 WARN  - Config error at <New class="org.eclipse.jetty.plus.jndi.EnvEntry"><Arg/><Arg>prop/someValue</Arg><Arg type="java.lang.String">hello</Arg><Arg type="boolean">true</Arg><Call name="bindToENC"><Arg>prop/someValue</Arg></Call></New> (org.eclipse.jetty.xml.XmlConfiguration)
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.jetty.util.TypeUtil.call(TypeUtil.java:538)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.call(XmlConfiguration.java:732)

有人知道怎么让它工作吗?

共有1个答案

萧建木
2023-03-14

您可以通过两种方式将prop/某些Value绑定到java: comp/env/prop/某些Value。第一个是这样引用web.xml中的环境条目:

<env-entry> 
   <env-entry-name>prop/someValue</env-entry-name> 
   <env-entry-type>java.lang.String</env-entry-type> 
   <env-entry-value>hello</env-entry-value> 
</env-entry>

但是,就像您的情况一样,您没有WEB-INF/WEB。根据J2EE,有效的web应用程序不需要xml。您可以使用bindToENC方法将绑定保留到Jetty。可以这样做:

<Configure id="server" class="org.eclipse.jetty.server.Server">
   <New class="org.eclipse.jetty.plus.jndi.EnvEntry">
      <Arg></Arg> <!-- Empty argument - scope set to JVM -->
      <Arg>prop/someValue</Arg>
      <Arg type="java.lang.String">hello</Arg>
      <Arg type="boolean">true</Arg>
      <Call name="bindToENC">
         <Arg>prop/someValue</Arg>
      </Call>
   </New>
</Configure>

所以你的错误是离开了

此外,为了让Jetty阅读Jetty env。xml文件,并包含启用jndi和plus模块所需的内容(必须同时启用这两个模块),如java-jar[jetty]/start。jar——添加到Jetty 9中的startd=jndi,再加上(模块之间没有空格),在以前的版本中,您可以在这里找到说明:http://wiki.eclipse.org/Jetty/Feature/JNDI#Detailed_Setup

 类似资料:
  • 问题内容: 我们有一个普通的独立spring应用程序,需要将jdbc数据源放在jndi中。(我们使用jboss treecache,它需要数据源位于jndi中)。 一些谷歌搜索人员发现了大多数使用Spring的jndi查找示例,其中已经在jndi中放置了一个对象(通过tomcat或应用服务器等),但是我们需要另外的方法:我有一个简单的数据源Spring bean,我将其注入到其他服务中,但我无法将

  • 问题内容: 我们有一个普通的独立spring应用程序,我们需要将jdbc数据源放在jndi中。(我们使用jboss treecache,它需要数据源位于jndi中)。 一些谷歌搜索人员发现了大多数使用Spring的jndi查找示例,其中已经在jndi中放置了一个对象(通过tomcat或应用程序服务器等),但是我们需要另外的方法:我有一个普通的数据源Spring bean,我将其注入到其他服务中,但

  • EJB 3.0提供了定义数据库实体关系/映射的选项,如一对一,一对多,多对一和多对多关系。 以下是相关注释 - One-to-One - 对象具有一对一的关系。 例如,乘客可以一次使用单张票。 One-to-Many - 对象具有一对多的关系。 例如,父亲可以有多个孩子。 Many-to-One - 对象具有多对一关系。 例如,多个孩子有一个单身母亲。 Many-to-Many - 对象具有多对多

  • JNDI代表Java命名和目录接口。 它是一组API和服务接口。 基于Java的应用程序使用JNDI进行命名和目录服务。 在EJB的上下文中,有两个术语。 Binding - 这是指为EJB对象分配名称,以后可以使用。 Lookup - 这是指查找并获取EJB的对象。 在Jboss中,会话bean默认以以下格式绑定在JNDI中。 local - EJB-name/local remote - EJ

  • 问题内容: 我正在尝试使用ng- model将复选框绑定到作用域。复选框的初始状态恰好与范围模型相对应,但是当我选中/取消选中复选框时,模型不会更改。需要注意的是,模板是在运行时使用ng- include动态加载的 当我选中该框时,控制台记录为false,而当我取消选中该框时,控制台再次记录为false。我还在作用域上有一个订单模型,如果我将复选框的模型更改为order.billing_is_sh

  • 为了更好地掌握AngularJS,我决定使用其中的一个示例,特别是简单地在Todo-example中添加一个“完整”的屏幕,当用户输入了5个todo,它使用一个switch-case切换到另一个div。代码可以在http://jsfiddle.net/fwchu/1/,如果有用的话。 但是,似乎每个switch-case都有自己的作用域($scope.todotext不可用),但是在本例中,可以从