SpringBeanAutowiringSupport in developing POJO endpoints using SimpleJaxWsServiceExporter does not seem to work
Environment
- JBoss Enterprise Application Platform (EAP)
- 5.x
- 6.0.0
- 6.0.1
- JBossWS-CXF
Issue
- Deployed a
@WebService
-annotated class to JBoss EAP 5.x, and configured a dependency injection in the endpoint classes. - To achieve and check proper injection that is performed, configured the
SpringBeanAutoWiringSupport
, but that does not seem to work. - Used Spring's
SimpleJaxWsServiceExporter
to publish the endpoints. - Invoking the underlying service with the client code results in
NullPointerException
on the Object(s) that are injected with the@Autowired
annotation. -
The sample application code looks like the following,
-
Service Interface:
package ws;
import org.springframework.stereotype.Service;
@Service("greetingService")
public interface GreetingService {
public String sayHello();
}
- Service Bean
package ws;
import org.springframework.stereotype.Component;
@Component
public class Greetings {
public String getGreeting() {
return "Welcome to MedCloudDataStore!!!";
}
}
- Service Endpoint
package ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@WebService(serviceName = "GreetingService")
public class GreetingServiceEndpoint extends SpringBeanAutowiringSupport implements GreetingService {
@Autowired
private Greetings greetings;
@WebMethod
public String sayHello() {
return greetings.getGreeting();
}
}
Resolution
Disable your SimpleJaxWsServiceExporter
and add the following code to your endpoint class(es):
import javax.annotation.PostConstruct;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@PostConstruct
public void init() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
Root Cause
The SimpleJaxWsServiceExporter
does not work as it expects in JBoss EAP. This class uses javax.xml.ws.Endpoint.publish()
to create its endpoints, but this is not intended to be used inside an EE container; it should only be used in standalone environments. The recommended method of deploying endpoints is to allow JBossWS deploy the endpoints.
What is really going on is that JBossWS is deploying the endpoint, and SimpleJaxWsServiceExporter
is failing silently. The error messages will likely be revealed in the logs if you add the system property -Dorg.jboss.as.logging.per-deployment=false
. The NullPointerException
is coming from the endpoint initialized by JBossWS, thus Spring's injection does not take place.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments