[英]@Inject raises NullPointerException in JAX-WS
我正在開發一個簡單的JAX-WS應用程序。
我的一個Web服務端點已經注入了對象
@WebService(
endpointInterface = "com.kravchenko.service.ClientService",
targetNamespace = "http://com.kravchenko/wsdl"
)
@Named("clientServiceImpl")
public class ClientServiceImpl implements ClientService {
@Inject
ClientDAO clientDAO;
public void addClient(Client client) {
if (clientDAO == null) {
System.out.println("NULL CLIENTDAO");
}
clientDAO.addClient(client);
}
}
當我通過soap調用其addClient(客戶端客戶端)方法時,它會引發NPE。
我的DAO也非常簡單,看起來像
@Singleton
public class ClientDAO {
public Map<Long,Client> clients= new ConcurrentHashMap<Long, Client>();;
public void addClient(Client client) {
clients.put(client.getId(),client);
}
}
我嘗試注射用於注射器注射的類型,但它也沒有用。 我還嘗試刪除@Singleton和/或使用其他注釋,如@ManagedBean或@Stateful,但NPE仍然存在。 我有sun-jaxws.xml有2個端點。 我的項目中有beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
如果我將其聲明為CliendDAO dao = new ClientDAO();
但這不是我希望我的代碼形成的方式。
我的pom.xml只有2個依賴項:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
請問我該如何解決這個問題?
基本上,我不得不從WEB-INF文件夾中刪除sun-jaxws.xml。 我不知道發生了什么,但肯定有影響 - CDI啟用了。 現在我的web.xml看起來像:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>soap</display-name>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>wsdl</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>wsdl</servlet-name>
<url-pattern>/clients</url-pattern>
</servlet-mapping>
</web-app>
為了獲得你的項目wsdl你可以按照下一個鏈接: / yourServiceName?wsdl
例如: http:// localhost:8080 / simplesoap / clients?wsdl使用WildFly或http:// localhost:8080 / clients?wsdl使用TomEE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.