Search code examples
nullpointerexceptiontomcat7managed-beaninject

Injecting Managed Bean into Webservice


I'm trying to inject a Managed Bean within a Webservice but the injected Bean is allways null. Does anybody knows why and if so could you provide some hints or a workaround?

@WebService(targetNamespace = "http://impl.soap.valueservice.drivelog.com/", endpointInterface = "com.drivelog.valueservice.soap.impl.ValueService", portName = "ValueServiceImplPort", serviceName = "ValueServiceImplService")
public class ValueServiceImpl implements ValueService {

    @Inject
    private ValueServiceFacade valueBean;

...
}

@ManagedBean
public class ValueServiceFacadeImpl implements ValueServiceFacade {
...
}

Solution

  • This is really embarrassing.

    According to this blog post (https://weblogs.java.net/blog/jitu/archive/2010/02/19/jax-ws-cdi-java-ee-6-0) and this post (https://blogs.oracle.com/arungupta/entry/totd_124_using_cdi_jpa), this should work but I can't make it work using TomEE here.

    There is also some discussion about JSRs here (https://bugzilla.redhat.com/show_bug.cgi?id=1001610) but I can't really tell you why it does not work.

    For TomEE (openEJB) all I could find was a lot of issues closed (related to https://issues.apache.org/jira/browse/OPENEJB-1592) with a scary comment "All done for certification", and maybe, the JEE Web Profile does not need to make these work together, while Geronimo, that implements the full EJB Profile, may need to work with this.

    Please also see Java EE 6 WebService and CDI injection

    So I can't really answer this. At the same time, I'll ask you to provide us some more information about what container you're using, so we can help you better.