user1376810
user1376810

Reputation:

Exposing JAX-WS web service as spring bean

Is this possible to somehow expose JAX-WS web service as spring bean? I need to set some objects into my implementation class, but I want to do this using spring.

Upvotes: 2

Views: 3522

Answers (1)

Paulius Matulionis
Paulius Matulionis

Reputation: 23415

You need to use SpringBeanAutowiringSupport and Autowired annotation to inject the object from spring. Create an endpoint class which will work like real web service but calls to real implementation methods goes throught your web service interface which is injected from spring.

For e.g:

@WebService(targetNamespace = "http://my.ws/MyWs",
        portName = "MyWsService",
        serviceName = "MyWs",
        endpointInterface = "my.ws.MyWsService",
        wsdlLocation = "WEB-INF/wsdl/MyWs.wsdl")
public class MyWsEndpoint extends SpringBeanAutowiringSupport implements MyWsService {

    @Autowired
    private MyWsService proxy;

    public void myMethod() {
        proxy.myMethod();
    }

}

Your JAX-WS enpoint configuration should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
    <endpoint
            name="MyWsService"
            implementation="my.ws.MyWsEndpoint"
            url-pattern="/services/MyWsService"/>
</endpoints>

Define real implementation class in spring but remember that both: your endpoint class and implementation class must implement your web service interface.

<bean id="myWsImpl" class="my.ws.MyWsImpl"/>

And thats it, now you can use spring in your JAX-WS web service.

Upvotes: 3

Related Questions