Community

Dependancy injection with datasources within a webservice

created by Jens Mander in JNDI and Naming - View the full discussion

Hi,

 

I'am trying to use the @Resouce-Annotation for a datasource in my WebService (wsdl). I guess the datasource is properly configured because the following snippet works without any problems.

 

 

public String myFunction(String in) throws NamingException {
 
        InitialContext ctx;
 
        ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:/MyDataSource");
 
        // do something with the datasource
        
        return "something";
    }

 

 

but if I'am trying something like that

 

@Resource(name="MyDataSource")
private DataSource ds;
 
public String myFunction(String in) throws NamingException {
 
        // do something with the datasource ds
        
        return "something";
    }
 

 

I can't even deploy my webservice to the JBoss AS. The message says  that "MyDataSource" couldn't be found ;(

I hope somebody has a piece of advice for me. Thanks a lot.

 

Jens

Reply to this message by going to Community

Start a new discussion in JNDI and Naming at Community