Ivan Kravchenko Ivan Kravchenko - 1 year ago 122
Java Question

@Inject raises NullPointerException in JAX-WS

I'm developing a simple JAX-WS application.

One of my web services endpoints has got injected object

endpointInterface = "com.kravchenko.service.ClientService",
targetNamespace = "http://com.kravchenko/wsdl"
public class ClientServiceImpl implements ClientService {

ClientDAO clientDAO;

public void addClient(Client client) {
if (clientDAO == null) {
System.out.println("NULL CLIENTDAO");

When I'm calling its addClient(Client client) method over soap it raises NPE.

My DAO is also very simple and looks like

public class ClientDAO {

public Map<Long,Client> clients= new ConcurrentHashMap<Long, Client>();;

public void addClient(Client client) {

I tried to injection type for setter injection, but it didn't work, too.
I also tried to remove @Singleton and/or use other annotations like @ManagedBean or @Stateful, however , NPE still remains.
I do have sun-jaxws.xml with 2 endpoints.
I do have beans.xml in my project:

<?xml version="1.0" encoding="UTF-8"?>

All DAO methods work though if I declare it as
CliendDAO dao = new ClientDAO();
But it's not the way I want my code to be formed.

my pom.xml has got only 2 dependencies:


Any idea how can I solve this problem, please?

Answer Source

Basically, I had to remove sun-jaxws.xml from WEB-INF folder. I have no idea what happened, but it definitely had impact - CDI became enabled. Now my web.xml looks like:

      <?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">




In order go obtain your project wsdl you can follow the next link: /yourServiceName?wsdl

For example: http://localhost:8080/simplesoap/clients?wsdl using WildFly or http://localhost:8080/clients?wsdl using TomEE

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download