Exposing servlet-based web services using JAX-WS:-
The Spring provides full support for standard Java web services APIs. Spring
provides a convenient base class for JAX-WS servlet endpoint
implementations - SpringBeanAutowiringSupport. To expose our DataService
we extend Spring’s SpringBeanAutowiringSupport class and implement our business
logic here, usually delegating the call to the business layer. We’ll simply use
Spring’s @Autowired annotation for expressing such dependencies on
Spring-managed beans.
import
org.springframework.web.context.support.SpringBeanAutowiringSupport;
@WebService(serviceName="DataService")
public class DataServiceEndpoint extends SpringBeanAutowiringSupport {
@Autowired
private DataService service;
@WebMethod
public void insertData(Data d) {
service.insertData(d);
}
@WebMethod
public Data[] getDat(String name) {
return service.getDat(name);
}}
The DataServletEndpoint needs to run in the same web application as the Spring context to allow for access to Spring’s facilities. This is the case by default in Java EE 5 environments, using the standard contract for JAX-WS servlet endpoint deployment.