将JAX-WS Web服务公开为Spring bean [英] Exposing JAX-WS web service as spring bean

查看:41
本文介绍了将JAX-WS Web服务公开为Spring bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以某种方式将JAX-WS Web服务公开为spring bean?我需要在实现类中设置一些对象,但是我想使用spring来实现.

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.

推荐答案

您需要使用SpringBeanAutowiringSupport和Autowired批注从spring注入对象.创建一个端点类,该端点类将像真实的Web服务一样工作,但是对真正的实现方法的调用将贯穿从Spring注入的Web服务接口.

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.

例如:

@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();
    }

}

您的JAX-WS enpoint配置应如下所示:

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>

在春季定义实际的实现类,但请记住,两者:您的终结点类和实现类必须实现您的Web服务接口.

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"/>

就这样,现在您可以在JAX-WS Web服务中使用spring.

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

这篇关于将JAX-WS Web服务公开为Spring bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆