View RSS Feed

Spring Framework

How to Export JAX-WS EndPoints in Spring

Rating: 3 votes, 4.67 average.
by , 11-28-2011 at 12:22 AM (10737 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:

Java Code:
<bean class= "org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"/>
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/.
One such bean that it may find is CarServiceEndpoint.

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;

@WebService(serviceName ="CarService")
public class CarServiceEndpoint {
	CarService carService;

	public void addCar(Car car) {

	public void deleteCar(Car car) {

	public List<Car> getCars(int carCount) {
		return carService.getCars(carCount);
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:
<bean class= "org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"
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.

Submit "How to Export JAX-WS EndPoints in Spring" to Facebook Submit "How to Export JAX-WS EndPoints in Spring" to Digg Submit "How to Export JAX-WS EndPoints in Spring" to Submit "How to Export JAX-WS EndPoints in Spring" to StumbleUpon Submit "How to Export JAX-WS EndPoints in Spring" to Google

Updated 11-30-2011 at 01:35 PM by Spring Framework

Web , Web Service , Spring 3