[jboss-user] [JBossWS] - Is it possible to inject a Datasource in a JBoss WS ?

dimar1975 do-not-reply at jboss.com
Thu Feb 12 05:29:06 EST 2009


Hi all !
I have posted this question in the persistence forum yesterday, but I had no luck. Meybe this forum is more appropriate: so 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 ???
The AS I0m using is JBoss 5.0 GA but I have tested also with 4.2 and it doesn't work too. :-(
Thanks a lot
Marco 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4209416#4209416

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4209416



More information about the jboss-user mailing list