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

    @Resource DataSource ds and @EJB injection not working

      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.

      public class CustomerWSImpl

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

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

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

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

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

      Your help is very much appreciated.
        • 1. Re: @Resource DataSource ds and @EJB injection not working
          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


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

          class MyWebService
               public IpcCoatService(){
               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