5 Replies Latest reply on Sep 14, 2007 7:18 PM by lent

    binding to local name space at startup

    lent

      Hi,

      I want to bind an object to local namespace at startup, similar to how datasources are bound to local namespace by specifying them in *ds.xml files. I know that it is possible to bind to the global namespace using JNDIBindingServiceMgr (in jboss-service.xml). Is it possible to bind to a local name in jboss-service.xml using some full path? For example, I want to be able to lookup java:jdbc/XXX in local namespace, is there some jndi-name I can specify in jboss-service.xml to bind to this? If not, can I achieve this through using a startup class or some other means?

      Regards,
      Len

        • 1. Re: binding to local name space at startup
          waynebaylor

          do you want to bind to the ENC (java:comp/env/jdbc/...) or to the JVM namespace (java:/...)?

          • 2. Re: binding to local name space at startup
            lent

            I want to bind to the ENC, i.e. the space from which EJBs typically look up datasources.

            Thanks,
            Len

            • 3. Re: binding to local name space at startup
              waynebaylor

              you can do two things:

              @Resource
              private DataSource ds;
              

              or
              ejb-jar.xml:
              <resource-ref>
               <description>DataSource</description>
               <res-ref-name>jdbc/MyDS</res-ref-name>
               <res-type>javax.sql.DataSource</res-type>
               <res-auth>Container</res-auth>
              </resource-ref>
              
              jboss.xml:
              <resource-ref>
               <res-ref-name>jdbc/MyDS</res-ref-name>
               <jndi-name>java:/MyDS</jndi-name>
              </resource-ref>
              
              your EJB code:
              Context ctx = new InitialContext();
              DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/MyDS");
              


              • 4. Re: binding to local name space at startup
                lent

                Wayne, thanks for your response. Actually, I want to bind to java:/ namespace, which is where it looks like data sources configured using *-ds.xml files wind up. I can't configure it in a ds.xml file because it is a custom data source.

                Thanks,
                Len

                • 5. Re: binding to local name space at startup
                  lent

                  I looked at the JNDI View in jmx-console and I'm finding that I am able to bind to the java:/ namespace from the jboss-service.xml (using JNDIBindingServiceMgr mbean). But I guess I'm approaching this the wrong way since I am binding the custom data source object under the right jndi name thinking this was all that is required but in fact it also needs to be recognized as a DataSourceBinding service in order for the dependency from my EJB to the data source (in the persistence-unit definition) to be resolved.

                  Len