【问题标题】:Exposing JAX-WS web service as spring bean将 JAX-WS Web 服务公开为 Spring Bean
【发布时间】:2012-05-05 13:29:10
【问题描述】:

这有可能以某种方式将 JAX-WS Web 服务公开为 Spring Bean 吗?我需要在我的实现类中设置一些对象,但我想使用 spring 来做到这一点。

【问题讨论】:

    标签: spring jax-ws


    【解决方案1】:

    您需要使用 SpringBeanAutowiringSupport 和 Autowired 注解从 spring 注入对象。创建一个端点类,它将像真正的 Web 服务一样工作,但对实际实现方法的调用会通过从 Spring 注入的 Web 服务接口。

    例如:

    @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 端点配置应如下所示:

    <?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>
    

    在 spring 中定义真正的实现类,但请记住:您的端点类和实现类都必须实现您的 Web 服务接口。

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

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

    【讨论】:

    • 完美。谢谢你。这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    相关资源
    最近更新 更多