2

これにより、JAX-WSWebサービスをSpringBeanとして公開することは可能ですか?いくつかのオブジェクトを実装クラスに設定する必要がありますが、これはSpringを使用して行いたいと思います。

4

1 に答える 1

3

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.

于 2012-05-05T13:32:18.247 に答える