【问题标题】:Spring 3 MVC + Web Services (JAX-WS)Spring 3 MVC + Web 服务 (JAX-WS)
【发布时间】:2012-10-12 14:16:41
【问题描述】:

我们有一个 Spring 3 MVC Web 应用程序,我们正在尝试使用 Web 服务对其进行扩展。

我现在尝试使用 JAX-WS Web 服务,在适当的位置注释 WebService 和 WebMethod。 我的 web.xml 中确实有一个调度程序。这是标准的 Spring DispatcherServlet。它的配置:dispatcher-servlet.xml 对于 MVC 的东西来说工作得很好。

当我尝试公开 WebServices 时,问题就来了。为此,我将以下 bean 添加到 dispatcher-servlet.xml:

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
    <property name="baseAddress" value="http://localhost:8080/service/" />
</bean>

如果添加了这个 bean。然后 WebServices 完美运行,但所有 MVC 东西都停止工作了。

所以我的第二次尝试是创建 2 个调度程序。一个名为 mvc-dispatcher 和一个 webservice-dispatcher。它们中的每一个都分别映射到 /mvc 和 /ws。然后只将 SimpleJaxWsServiceExporter 放在 webservice-config 中,只将标准 MVC 东西放在另一个中。 但还是同样的问题。 如果我禁用/注释掉 Web 服务调度程序,我只能让 MVC 工作。

我不敢相信这应该如此复杂......我没有得到什么?

任何帮助将不胜感激。 我找不到任何像样的 JAX-WS 和 spring 3 MVC 教程...

提前致谢!

【问题讨论】:

    标签: web-services spring-mvc jax-ws


    【解决方案1】:

    我假设调度员是指弹簧调度员,我建议不要这样做。只需让 JAX-WS 自己成为一个不同的 servlet,即

    https://cwiki.apache.org/GMOxDOC20/simple-web-service-with-jax-ws.html

    那么如果您需要允许注入 Spring bean,请扩展 SpringBeanAutowiringSupport,如本例所示。

    How to make an @WebService spring aware

    希望这会有所帮助!

    【讨论】:

    • 酷。并感谢您的回答。我将在星期一测试这种方法!我会带着结果回来的。
    • 今天刚试过,但由于某种原因,它不适用于您建议的方法。但我发现了另一个完美的工作。我刚刚按照本教程进行操作,它与 spring mvc 配合得非常好! mkyong.com/webservices/jax-ws/…
    【解决方案2】:

    可以使用实现JAXWS规范的Apache CXF,与Spring有很好的集成,其实CXF在幕后使用Spring。

    实际上,您可以这样进行:

    在您的 web.xml 中,您已将 cxf servlet 配置如下

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
              http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
               version="3.0">
    
    ....
        <servlet>
            <description>Apache CXF Endpoint</description>
            <display-name>cxf</display-name>
            <servlet-name>cxf</servlet-name>
            <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>cxf</servlet-name>
            <url-pattern>/ws/*</url-pattern>
        </servlet-mapping>
    
    
    </web-app>
    

    Apache CXF 配置

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:jaxws="http://cxf.apache.org/jaxws"
           xmlns:jaxrs="http://cxf.apache.org/jaxrs"
           xmlns:soap="http://cxf.apache.org/bindings/soap"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                               http://cxf.apache.org/jaxws
                               http://cxf.apache.org/schemas/jaxws.xsd
                               http://cxf.apache.org/jaxrs
                               http://cxf.apache.org/schemas/jaxrs.xsd
                               http://cxf.apache.org/bindings/soap
                               http://cxf.apache.org/schemas/configuration/soap.xsd">
    
        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath*:META-INF/cxf/cxf-extension-*.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    
        <jaxws:endpoint
                id="yourService"
                implementor="#yourService"
                address="/yourAddres">
        </jaxrs:server>
    </beans>
    

    你的豆子

     @Service
        @WebService(serviceName = "soapSvnClientService")
        public class SoapSvnClientService {
    
            @WebMethod(operationName = "service")
            public void service(@WebParam String param1,
                               @WebParam String param2){
    
        ....
        }
    
     }
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      相关资源
      最近更新 更多