2012-10-12 73 views
2

我們有一個Spring 3 MVC Web應用程序,我們正試圖用Web服務來擴展它。Spring 3 MVC + Web服務(JAX-WS)

我現在已經嘗試使用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。然後在webservice-config中只放入SimpleJaxWsServiceExporter,而在另一箇中只放置標準的MVC。 但仍然是同樣的問題。 如果我禁用/註銷Web服務調度程序,我只能讓MVC工作。

我不敢相信這應該是如此複雜......我沒有得到什麼?

任何幫助將大大appriciated。 我無法找到任何像樣的教程做JAX-WS和春季3 MVC ...

在此先感謝!

回答

2

我假設調度員你的意思是一個春季調度員,我會建議對此。只是有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

希望這有助於!

+0

很酷。並感謝您的回答。我會在星期一測試這種方法!我會回來的結果。 – user829237

+0

今天剛剛嘗試過,但由於某種原因,它不適用於您建議的方法。但我發現另一個完美的工作。我只是按照這個教程,它彈簧mvc非常好! http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/ – user829237

1

你可以使用Apache CXF實現的JAXWS Specification與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> 

你的bean

@Service 
    @WebService(serviceName = "soapSvnClientService") 
    public class SoapSvnClientService { 

     @WebMethod(operationName = "service") 
     public void service(@WebParam String param1, 
          @WebParam String param2){ 

    .... 
    } 

} 

我希望這可以幫到你