JNDI look up......

Discussions

EJB design: JNDI look up......

  1. JNDI look up...... (4 messages)

    Hi,

      To get DataSource object of a connection pool which I cerated in weblogic 7.0, I can do JNDI loop in two ways...

    1.DataSource ds = (DataSource) ic.lookup("sampleConnPool");
     where "sampleConnPool" is the JNDI name of the pool which i created....

    2. private String dbName = "java:comp/env/jdbc/sampleConnPool";
    where "java:comp/env/jdbc/sampleConnPool" is having entry in ejb-jar.xml
     <resource-ref>
            <res-ref-name>jdbc/sampleConnPool</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
    </resource-ref>

    DataSource ds = (DataSource) ic.lookup(dbName);


    can somebody tell me what is the difference between two ways of doing JNDI lookup...

    --Suresh

    Threaded Messages (4)

  2. JNDI look up......[ Go to top ]

    Although both approaches are valid there are some slight differences. The first approach looks up the datasource directly in the jndi tree while the second approach goes through the ejb enc to look up the datasource. When resource references are declared in ejb, those references are local only to the bean they are declared in. So the reference declared in the second approach is only visible to the ejb declaration that contains it. This provides a layer of indirection which may be useful for resolving conflicts.
  3. JNDI look up......[ Go to top ]

    Hi,
      
       Thanxs, Can, u explain the statement in detail "This provides a layer of indirection which may be useful for resolving conflicts"....

    --Thanks\suresh
  4. also look at weblogic-ejb-jar.xml[ Go to top ]

    There's a 2nd xml file that's appserver specific and while by default you'll have the same names there, it allows you the option of having a generic name in the code java:comp/env/jdbc/MyDataSource but at deploy time, specify exactly which 'real' datasource that it linked to.

    How much this is of use comes down to how generic/re-usable your bean/environment needs to be...
  5. jndi.properties file[ Go to top ]

    interesting to know the diff. in the two approaches...

    we can use jndi.properties file to describe:
    // WEB-INF/classes/jndi.properties
    java.naming.factory.initial=WLInitialContextFactory

    java.naming.provider.url=t3://localhost:port/<application>
    //java.naming.security.principal=<username>
    //java.naming.security.credentials=<password>
    to make the code generic..