帮助在Tomcat 5.5.x中使用嵌入式JBoss配置JNDI

时间:2022-09-30 20:02:19

When I try the following lookup in my code:

当我在我的代码中尝试以下查找时:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
return (DataSource) envCtx.lookup("jdbc/mydb"); 

I get the following exception:

我得到以下异常:

java.sql.SQLException: QueryResults: Unable to initialize naming context: 
    Name java:comp is not bound in this Context at 
    com.onsitemanager.database.ThreadLocalConnection.getConnection
    (ThreadLocalConnection.java:130) at     
    ...

I installed embedded JBoss following the JBoss wiki instructions. And I configured Tomcat using the "Scanning every WAR by default" deployment as specified in the configuration wiki page.

我按照JBoss wiki说明安装了嵌入式JBoss。我使用配置维基页面中指定的“默认扫描每个WAR”部署配置Tomcat。

Quoting the config page:

引用配置页面:

JNDI

Embedded JBoss components like connection pooling, EJB, JPA, and transactions make extensive use of JNDI to publish services. Embedded JBoss overrides Tomcat's JNDI implementation by layering itself on top of Tomcat's JNDI instantiation. There are a few > reasons for this:

嵌入式JBoss组件(如连接池,EJB,JPA和事务)广泛使用JNDI来发布服务。嵌入式JBoss通过在Tomcat的JNDI实例化之上分层来覆盖Tomcat的JNDI实现。有几个原因:

  1. To avoid having to declare each and every one of these services within server.xml
  2. 避免必须在server.xml中声明这些服务中的每一个

  3. To allow seemeless integration of the java:comp namespace between web apps and EJBs.
  4. 允许在web应用程序和EJB之间无缝集成java:comp命名空间。

  5. Tomcat's JNDI implementation has a few critical bugs in it that hamper some JBoss components ability to work
  6. Tomcat的JNDI实现中存在一些严重错误,阻碍了一些JBoss组件的工作能力

  7. We want to provide the option for you of remoting EJBs and other services that can > be remotely looked up
  8. 我们希望为您提供远程查找远程查找EJB和其他服务的选项

Anyone have any thoughts on how I can configure the JBoss naming service which according to the above quote is overriding Tomcat's JNDI implementation so that I can do a lookup on java:comp/env?

任何人都有任何关于如何配置JBoss命名服务的想法,根据上面的引用覆盖Tomcat的JNDI实现,以便我可以在java:comp / env上进行查找?

FYI - My environment Tomcat 5.5.9, Seam 2.0.2sp, Embedded JBoss (Beta 3),

仅供参考 - 我的环境Tomcat 5.5.9,Seam 2.0.2sp,嵌入式JBoss(Beta 3),

Note: I do have a -ds.xml file for my database connection properly setup and accessible on the class path per the instructions.

注意:我的数据库连接正确设置了-ds.xml文件,并且可以按照说明在类路径*问。

Also note: I have posted this question in embedded Jboss forum and seam user forum.

另请注意:我已在嵌入式Jboss论坛和缝用户论坛中发布此问题。

3 个解决方案

#1


2  

Thanks for the response toolkit.... yes, I can access my datasource by going directly to java:jdbc/mydb, but I'm using an existing code base that connects via the ENC. Here's some interesting info that I've found out ....

感谢响应工具包....是的,我可以通过直接访问java:jdbc / mydb来访问我的数据源,但我正在使用通过ENC连接的现有代码库。这是我发现的一些有趣的信息....

  1. The above code works with JBoss 4.2.2.GA and here's the JNDI ctx parameters being used:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces: org.jboss.naming:org.jnp.interfaces

    上面的代码适用于JBoss 4.2.2.GA,这里是使用的JNDI ctx参数:java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs = org.jboss.naming :org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces

  2. The above code works with Tomcat 5.5.x and here's the JNDI ctx parameters being used:
    java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs=org.apache.naming

    上面的代码适用于Tomcat 5.5.x,这里是使用的JNDI ctx参数:java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs = org.apache.naming

  3. The above code fails with Embedded JBoss (Beta 3) in Tomcat 5.5.x with the above error message.
    java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs=org.apache.namingThe above code fails with the above error using JBoss Embedded in tomcat 5.5.x

    以上代码在Tomcat 5.5.x中使用嵌入式JBoss(Beta 3)失败,并显示以上错误消息。 java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs = org.apache.naming上面的代码在tomcat 5.5.x中使用JBoss Embedded时出现上述错误失败

Anyone have any thoughts I what I need to do with configuring embedded JBoss JNDI configuration?

任何人都有任何想法我需要做什么配置嵌入式JBoss JNDI配置?

#2


1  

java:comp/env is known as the Enterprise Naming Context (ENC) and is not globally visible. See here for more information. You will need to locate the global JNDI name which your datasource is regsitered at.

java:comp / env称为企业命名上下文(ENC),并不是全局可见的。浏览此处获取更多信息。您需要找到数据源注册的全局JNDI名称。

The easiest way to do this is to navigate to JBoss' web-based JMX console and look for a 'JNDIView' (not exactly sure of the name - currently at home) mbean. This mbean should have a list method which you can invoke, which will display the context path for all of the JNDI-bound objects.

最简单的方法是导航到JBoss基于Web的JMX控制台,并寻找一个'JNDIView'(不完全确定名称 - 目前在家里)mbean。这个mbean应该有一个可以调用的列表方法,它将显示所有JNDI绑定对象的上下文路径。

#3


1  

I had some similar issue with Jboss Embedded and i finally fix playing in the file: test-Datasource-ds.xml

我和Jboss Embedded有一些类似的问题,我终于修复了文件:test-Datasource-ds.xml

adding

<mbean code="org.jboss.naming.NamingAlias" name="jboss.jmx:alias=testDatasource">
    <attribute name="FromName">jdbc/Example DataSource</attribute>
    <attribute name="ToName">java:/testDatasource</attribute>
</mbean>

The problem was jboss add the prefix java:/ for all data source declared. So finally i had a datasource named testDatasource, overrided with that directive to jdbc/Example DataSource

问题是jboss为声明的所有数据源添加前缀java:/。所以最后我得到了一个名为testDatasource的数据源,用该指令覆盖了jdbc / Example DataSource

Hope it works

希望它有效

#1


2  

Thanks for the response toolkit.... yes, I can access my datasource by going directly to java:jdbc/mydb, but I'm using an existing code base that connects via the ENC. Here's some interesting info that I've found out ....

感谢响应工具包....是的,我可以通过直接访问java:jdbc / mydb来访问我的数据源,但我正在使用通过ENC连接的现有代码库。这是我发现的一些有趣的信息....

  1. The above code works with JBoss 4.2.2.GA and here's the JNDI ctx parameters being used:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces: org.jboss.naming:org.jnp.interfaces

    上面的代码适用于JBoss 4.2.2.GA,这里是使用的JNDI ctx参数:java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs = org.jboss.naming :org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces

  2. The above code works with Tomcat 5.5.x and here's the JNDI ctx parameters being used:
    java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs=org.apache.naming

    上面的代码适用于Tomcat 5.5.x,这里是使用的JNDI ctx参数:java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs = org.apache.naming

  3. The above code fails with Embedded JBoss (Beta 3) in Tomcat 5.5.x with the above error message.
    java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs=org.apache.namingThe above code fails with the above error using JBoss Embedded in tomcat 5.5.x

    以上代码在Tomcat 5.5.x中使用嵌入式JBoss(Beta 3)失败,并显示以上错误消息。 java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs = org.apache.naming上面的代码在tomcat 5.5.x中使用JBoss Embedded时出现上述错误失败

Anyone have any thoughts I what I need to do with configuring embedded JBoss JNDI configuration?

任何人都有任何想法我需要做什么配置嵌入式JBoss JNDI配置?

#2


1  

java:comp/env is known as the Enterprise Naming Context (ENC) and is not globally visible. See here for more information. You will need to locate the global JNDI name which your datasource is regsitered at.

java:comp / env称为企业命名上下文(ENC),并不是全局可见的。浏览此处获取更多信息。您需要找到数据源注册的全局JNDI名称。

The easiest way to do this is to navigate to JBoss' web-based JMX console and look for a 'JNDIView' (not exactly sure of the name - currently at home) mbean. This mbean should have a list method which you can invoke, which will display the context path for all of the JNDI-bound objects.

最简单的方法是导航到JBoss基于Web的JMX控制台,并寻找一个'JNDIView'(不完全确定名称 - 目前在家里)mbean。这个mbean应该有一个可以调用的列表方法,它将显示所有JNDI绑定对象的上下文路径。

#3


1  

I had some similar issue with Jboss Embedded and i finally fix playing in the file: test-Datasource-ds.xml

我和Jboss Embedded有一些类似的问题,我终于修复了文件:test-Datasource-ds.xml

adding

<mbean code="org.jboss.naming.NamingAlias" name="jboss.jmx:alias=testDatasource">
    <attribute name="FromName">jdbc/Example DataSource</attribute>
    <attribute name="ToName">java:/testDatasource</attribute>
</mbean>

The problem was jboss add the prefix java:/ for all data source declared. So finally i had a datasource named testDatasource, overrided with that directive to jdbc/Example DataSource

问题是jboss为声明的所有数据源添加前缀java:/。所以最后我得到了一个名为testDatasource的数据源,用该指令覆盖了jdbc / Example DataSource

Hope it works

希望它有效