How to Export JAX-WS EndPoints in Spring
by , 11-28-2011 at 12:22 AM (6263 Views)
In my previous tip, I showed you how to autowire a JAX-WS endpoint. Although this is very useful, but recognize that the objects whose properties are being injected doesn’t have its lifecycle managed by Spring. There are circumstances though, where it’s possible to export a Spring-managed bean as a JAX-WS endpoint. In this tip, I will show you how.
Spring’s SimpleJaxWsServiceExporter works by publishing Spring-managed beans as service endpoints in a JAX-WS runtime. SimpleJaxWsServiceExporter doesn’t need to be given a reference to the bean it’s exporting. Instead, it publishes all beans that are annotated with JAX-WS annotations as JAX-WS services. SimpleJaxWsServiceExporter can be configured using the following <bean> declaration:
SimpleJaxWsServiceExporter doesn’t require anything to do its job. When it starts, it’ll search through the Spring application context looking for beans that are annotated with @WebService. When it finds one, it’ll publish it as a JAX-WS endpoint with a base address of http://localhost:8080/.Java Code:<bean class= "org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"/>
One such bean that it may find is CarServiceEndpoint.
The key difference with the Spring enable JAX-WS endpoints is that it doesn’t extend the SpringBeanAtowiringSupport. It can by autowired without use of extending any special support class. As the base address of SimpleJaxWsServiceEnpoint defaults to http://localhost:8080 and the CarServiceEnpoint is annotated with @WebService(serviceName=CarService), the combination of these beans will result in the web service being located at http://localhost/CarService. You could modify this if you like by changing the service URL by specifying another base address for the SimpleJaxWsServiceExporter:Java Code:package com.acme.springwebapp.remoting.jaxws; import java.util.List; import javax.jws.WebMethod; import javax.jws.WebService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.acme.springwebapp.domain.Car; import com.acme.springwebapp.service.CarService; @Component @WebService(serviceName ="CarService") public class CarServiceEndpoint { @Autowired CarService carService; @WebMethod public void addCar(Car car) { carService.addCar(car); } @WebMethod public void deleteCar(Car car) { carService.deleteCar(car); } @WebMethod public List<Car> getCars(int carCount) { return carService.getCars(carCount); } }
This would lead to a service endpoint to http://localhost:8888/services/CarService. In the next tip, I will look at proxying JAX-WS services on the client side.Java Code:<bean class= "org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter" p:baseAddress="http://localhost:8888/services/"/>










Email Blog Entry
Size Reduced for Images in PDF &...
05-15-2013, 05:53 PM in Java Software