5 Replies Latest reply on Jul 23, 2009 11:02 AM by jaikiran pai

    Datasource injection not working on Web Services ?

    ermes martino Newbie

      Hi all !
      I'm trying to inject a Datasource in a Webservice....

      @WebService(name = "CalculatorWS", targetNamespace = "http://webservice_calc/calculator")
      public class CalculatorWS
      {
       @Resource(mappedName="java:/OracleDS")
       DataSource datasource;
      
       @WebMethod
       public Person calculate(Object obj) {
       System.out.println("Datasource is " + datasource; // NULL !!
       // .....
       }
      }



      The Datasource injected is null in the method calculate.....
      so I have tried to get the datasource with the InitialContext


      DataSource ds = (DataSource)new InitialContext().lookup("java:/OracleDS");
      
      Connection conn = null;
      try {
      
      conn = ds.getConnection();
      System.out.println("Connection with initial context" +conn);
      }



      and the Connection is correctly retrieved.

      Do I miss something to make it work also with injection ???
      Thanks a lot
      Marco