问题描述
为什么以下CDI在Glassfish 3.x.x的JAX-WS端点中不起作用?从端点访问服务时得到NPE。
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.");
}
}
我在WEB-中有一个空的beans.xml文件, INF。我尝试使用完全空内容和空
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>
标签。但是以某种方式,JAX-WS端点中的服务字段在部署后和接收Web服务请求期间仍为NULL,从而在调用服务时导致NPE。我在这里错过了什么?
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?
推荐答案
是的,我通过删除sun-jaxws.xml并修改了指向我的web.xml使其工作了
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>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- This listener parses a sun specific configuration file (sun-jaxws.xml), which provides the web service
endpoints and connects the WSServlet instance to the services' implementation classes -->
<!--<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener> -->
<!-- Delegate requests whose URLs end with the path '/StakeholderWebService' to a WSServlet instance provided by container, which in turn is linked to the JWS runtime -->
<servlet>
<servlet-name>StakeholderWebService</servlet-name>
<!-- <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> -->
<servlet-class>com.werner.stakeholder.webservices.StakeholderWebServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StakeholderWebService</servlet-name>
<url-pattern>/stakeholderWebService</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
这篇关于JAX-WS端点中的CDI注入不起作用,导致NPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!