1 Reply Latest reply on May 21, 2008 6:58 AM by 666705

    @Resource DataSource ds and @EJB injection not working

    666705
      Hi there,
      I'm using wls 10.3 and I'm trying to inject a DataSource and EJB in one of my webservice (jax-rpc) and using the annotation because I'm just using the jwsc ant task to generate all my weblogic descriptor. When I tried to test the DataSource and EJB it is null. I have defined in the admin console a jdbc DataSource jndi named="jdbc/ppDataSource" and also created both SystemEJBRemote and SystemEJBLocal ejb's. Sample code below.

      @SoapBinding(style=SOAPBinding.Style.DOCUMENT....)
      @Stateless(mappedName="CustomerBeanWS")
      @WebService(name="CustomerWS",
      serviceName="CustomerWSService")
      public class CustomerWSImpl

      @EJB private SystemEJBLocal systemLocal;
      @Resource DataSource(name="jdbc/DataSource") ds;

      public void testInjection() {
      // test ejb
      if (systemLocal != null) {
      systemLocal.hello();
      } else {
      System.out.println("SystemEJBLocal ref injection is null.");
      }

      if (ds != null) {
      ds.getConnection();
      } else {
      System.out.println("DataSource ref injection is null.");
      }
      }

      @Stateless
      @Local( SystemEJBLocal.class )
      @Remote( SystemEJBRemote.class )
      public class SystemEJBImpl {

      public void hello() {
      System.out.println( "Hello EJB3!" );
      }
      }

      Your help is very much appreciated.
      Thanks
        • 1. Re: @Resource DataSource ds and @EJB injection not working
          666705
          Hi,
          unfortunatly i had the same problem for ejb injection.
          i resolved this with the following not nice workaround

          Auto wire does not work with pojos.
          So i used the declaration of references in the web.xml. The problem here is, the web.xml is automatically generated by the jwsc - ant task.

          So I added to the existing web.xml the following lines

               <ejb-local-ref>
                    <ejb-ref-name>ejb/IntegratorManager</ejb-ref-name>
                    <ejb-ref-type>Session</ejb-ref-type>
                    <local>com.abc.ipc.integrator.services.IntegratorManager</local>
                    <ejb-link>IntegratorManagerBean</ejb-link>
               </ejb-local-ref>

          In my WebService, i looked up the Session Bean and it works fine.

          class MyWebService
               public IpcCoatService(){
                    this.lookupIntegrationManager();
               }
               
               private IntegratorManager iManager;          
               
               private void lookupIntegrationManager(){
                    try {
                         Context ctx = new InitialContext();
                         this.iManager = (IntegratorManager) ctx.lookup("java:comp/env/ejb/IntegratorManager");
                         
                    } catch (NamingException nExc) {
                         myLogger.severe("Namingexception when lookup session bean " + nExc.getMessage() );
                    }
               }

          So i only have to solve the problem, to add the reference to the web.xml automatically.

          hope this will help
          bye
          karpuz