Configuring JNDI with built-in JBoss in Tomcat 5.5.x

When I try to do the following search 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 the built-in JBoss according to the instructions of the JBoss wiki . And I configured Tomcat using the "Scan each WAR by default" deployment, as indicated on the wiki page .

Quote configuration page:

Jndi

JBoss embedded components, such as pooling, EJB, JPA, and transactions, make extensive use of JNDI to publish services. Built-in JBoss overrides the Tomcat JNDI implementation by splitting itself on top of the Tomcat JNDI instance. There are several reasons for this:

  • To avoid declaring each of these services in server.xml
  • java: comp - EJBs.
  • Tomcat JNDI , JBoss
  • EJB , .

- , JBoss, Tomcat JNDI, java: comp/env?

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

. -ds.xml , .

: Jboss .

+5
3

.... , , java: jdbc/mydb, , ENC. , ....

  • JBoss 4.2.2.GA, JTDI 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

  • Tomcat 5.5.x, JTDI ctx:
    java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs = org.apache.naming

  • Embedded JBoss (Beta 3) Tomcat 5.5.x .
    java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory java.naming.factory.url.pkgs = org.apache.naming , JBoss Embedded tomcat 5.5.x

- , JBoss JNDI?

+2

java: comp/env (ENC) . . . JNDI, .

- JMX- JBoss "JNDIView" ( - ) mbean. mbean , , , JNDI.

+1

Jboss Embedded, , , : -Datasource-ds.xml

<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>

, jboss java:/ . , , testDatasource, jdbc/Example DataSource

, .

+1
source

All Articles