为什么以下CDI在glassfish 3.x.x中的JAX-WS端点中不起作用?从端点访问服务时,我得到一个NPE。
@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 + ".";
}
}
“服务”类定义如下:
@Named("myService")
public class MyService {
public MyService() {
System.out.println("init myService.");
}
public void callService() {
System.out.println("calling Service.");
}
}
我在WEB-INF中有一个空的beans.xml文件。我用完整的空内容和空的
尝试了它<?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。我在这里缺少什么?
答案 0 :(得分:1)
您可以尝试从WEB-INF目录中删除sun-jaxws.xml。这种方式帮助了我!
答案 1 :(得分:1)
是的,我通过删除sun-jaxws.xml并修改web.xml直接指向我的webservice而不是WSServlet来实现它。
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“&GT;
<!-- 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>