5 Replies Latest reply on Dec 7, 2005 12:29 AM by Denis Kostousov

    Configure datasource mapping

    Denis Kostousov Newbie

      How I cat configure datasource mapping?

      My stateless bean (ejb3) have this strings:

      @Stateless(name="StatLoaderSEJB3")
      @RemoteBinding(jndiBinding="StatLoaderSEJB3")
      public class StatLoaderSEJB3 implements IStatLoader{
      ...
       @Resource(name="java:comp/env/jdbc/StatDS")
       private DataSource ds=null;
      ...
      }
      

      There is global datasource "java:/RadiusDS"

      I tried to configure resource mapping via jboss.xml:
      <?xml version='1.0' encoding='UTF-8'?>
      <jboss>
       <enterprise-beans>
       <session>
       <ejb-name>StatLoaderSEJB3</ejb-name>
       <resource-ref>
       <res-ref-name>java:comp/env/jdbc/StatDS</res-ref-name>
       <jndi-name>java:/RadiusDS</jndi-name>
       <!--<res-type>javax.sql.DataSource</res-type>-->
       </resource-ref>
       </session>
       </enterprise-beans>
      </jboss>
      


      When I deploy myapp.ejb3 to Jboss, I saw there message:
      15:37:59,803 WARN [ResourceHandler] Unbound injected resource interface javax.sql.DataSource ds
      

      What I did whong?

        • 1. Re: Configure datasource mapping
          Kabir Khan Master

          I think

          @Stateless(name="StatLoaderSEJB3")
          @RemoteBinding(jndiBinding="StatLoaderSEJB3")
          public class StatLoaderSEJB3 implements IStatLoader{
          ...
           @Resource(name="jdbc/StatDS")
           private DataSource ds=null;
          ...
          }
          


          <?xml version='1.0' encoding='UTF-8'?>
          <jboss>
           <enterprise-beans>
           <session>
           <ejb-name>StatLoaderSEJB3</ejb-name>
           <resource-ref>
           <res-ref-name>jdbc/StatDS</res-ref-name>
           <jndi-name>java:/RadiusDS</jndi-name>
           <!--<res-type>javax.sql.DataSource</res-type>-->
           </resource-ref>
           </session>
           </enterprise-beans>
          </jboss>
          


          should work.


          You can also do enc to global jndi mapping using @Resource.mappedName directly:

          @Stateless(name="StatLoaderSEJB3")
          @RemoteBinding(jndiBinding="StatLoaderSEJB3")
          public class StatLoaderSEJB3 implements IStatLoader{
          ...
           @Resource(name="jdbc/StatDS", mappedName="java:/RadiusDS")
           private DataSource ds=null;
          ...
          }
          


          • 2. Re: Configure datasource mapping
            Denis Kostousov Newbie

            I tried both cases.
            1. Nothing changed
            2. error: cannot find symbol method mappedName()

            If I use

            @Resource(name="java:/RadiusDS")
            

            all work rightly

            How I can view JNDI namespace of my ejb3 module? Jboss service JNDIView don't display it (because StatLoaderSEJB3 local namespace is empty?).

            • 3. Re: Configure datasource mapping
              Kabir Khan Master

              Which version are you using? There have been some changes in the spec, so what I have put should work with the latest release. If not, definitely with the next.

              "Your way" is how it worked before.

              • 4. Re: Configure datasource mapping
                Denis Kostousov Newbie

                CVSTag=JBoss_4_0_3_SP1 date=200510231751

                • 5. Re: Configure datasource mapping
                  Denis Kostousov Newbie

                  I downloaded EJB3.0RC3 ?nd installed it in JBoss 4.0.3sp1
                  Now, this is work

                  ...
                   @Resource(name="jdbc/StatDS", mappedName="java:/RadiusDS")
                   private DataSource ds=null;
                  ...
                  


                  but, if I try to configure mapping via jboss.xml
                   <session>
                   <ejb-name>StatLoaderSEJB3</ejb-name>
                   <resource-ref>
                   <res-ref-name>jdbc/StatDS</res-ref-name>
                   <jndi-name>java:/RadiusDS</jndi-name>
                   <!--<res-type>javax.sql.DataSource</res-type>-->
                   </resource-ref>
                   </session>
                  

                  I get expetion
                  10:17:30,510 INFO [Ejb3DescriptorHandler] found jboss.xml jar:file:/usr/local/java/jboss-4.0.3SP1/server/ejb3/tmp/deploy/tmp54685office.ear-contents/office.ejb3!/META-INF/jboss.xml
                  10:17:30,538 WARN [ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=office.ejb3
                  org.jboss.xb.binding.JBossXBException: Failed to parse source.
                   at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:138)
                   at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173)
                   at org.jboss.ejb3.Ejb3DescriptorHandler.parseDescriptors(Ejb3DescriptorHandler.java:571)
                   at org.jboss.ejb3.Ejb3HandlerFactory$DDFactory.<init>(Ejb3HandlerFactory.java:19)
                   at org.jboss.ejb3.Ejb3HandlerFactory.getInstance(Ejb3HandlerFactory.java:54)
                   at org.jboss.ejb3.Ejb3Deployment.deploy(Ejb3Deployment.java:274)
                   at org.jboss.ejb3.Ejb3Deployment.create(Ejb3Deployment.java:262)
                   at org.jboss.ejb3.Ejb3JmxDeployment.create(Ejb3JmxDeployment.java:230)
                   at org.jboss.ejb3.Ejb3Module.createService(Ejb3Module.java:34)
                   at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:245)
                   at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:228)
                   at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:585)
                   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                   at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:943)
                   at $Proxy0.create(Unknown Source)
                   at org.jboss.system.ServiceController.create(ServiceController.java:341)
                   at org.jboss.system.ServiceController.create(ServiceController.java:284)
                   at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:585)
                   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                   at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
                   at $Proxy10.create(Unknown Source)
                   at org.jboss.ejb3.EJB3Deployer.create(EJB3Deployer.java:200)
                   at org.jboss.deployment.MainDeployer.create(MainDeployer.java:935)
                   at org.jboss.deployment.MainDeployer.create(MainDeployer.java:925)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:789)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:753)
                   at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:585)
                   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                   at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118)
                   at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                   at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
                   at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
                   at $Proxy6.deploy(Unknown Source)
                   at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:319)
                   at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:489)
                   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:192)
                   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:203)
                   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182)
                  Caused by: java.lang.NullPointerException
                   at org.jboss.ejb3.dd.EnterpriseBeans.setJndiName(EnterpriseBeans.java:78)
                   at org.jboss.ejb3.dd.JBossDDObjectFactory.setValue(JBossDDObjectFactory.java:404)
                   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:585)
                   at org.jboss.xb.binding.ObjectModelBuilder.invokeFactory(ObjectModelBuilder.java:421)
                   at org.jboss.xb.binding.DelegatingObjectModelFactory.setValue(DelegatingObjectModelFactory.java:144)
                   at org.jboss.xb.binding.ObjectModelBuilder.endElement(ObjectModelBuilder.java:360)
                   at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.endElement(SaxJBossXBParser.java:212)
                   at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
                   at org.apache.xerces.impl.dtd.XMLNSDTDValidator.endNamespaceScope(Unknown Source)
                   at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
                   at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
                   at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
                   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
                   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
                   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
                   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
                   at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
                   at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:134)
                   ... 55 more