Why doesn't the following CDI work in JAX-WS endpoints in glassfish 3.x.x? I get an NPE when accessing the service from the endpoint.
@WebService
public class JaxWsTestEndpoint {
@Inject
private MyService service;
@WebMethod
public String sayHello(String name) {
System.out.println("injected service:" + service);
service.callService();
return "Hello, " + name + ".";
}
}
Where the class "service" is defined as follows:
@Named("myService")
public class MyService {
public MyService() {
System.out.println("init myService.");
}
public void callService() {
System.out.println("calling Service.");
}
}
I have an empty beans.xml file in WEB-INF. I tried it with complete empty content, and with an empty
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
tag. But somehow, the service field in the JAX-WS endpoint is still NULL after deployment and during receiving a web service request, resulting in a NPE when calling the service. What am i missing here?
You can try to remove sun-jaxws.xml from WEB-INF directory. This way has helped me!
Yes I got it working by removing sun-jaxws.xml and modifying web.xml pointing my webservice directly instead of WSServlet.
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">