Can I use Spring MVC and Spring WS in one single application?

耗尽温柔 提交于 2019-11-27 12:20:18

问题


Basically there is a back-end application that is exposing both SOAP as well as RESTful services.

I have decided to use Spring WS 1.5.8 for SOAP services, and
Spring MVC 3.0 for RESTful services as this is a new feature.

upon reading a bit about Spring WS (I am new to this!) we got to declare a "MessageDispatcherServlet" which is a front controller, in web.xml for Spring WS.

For Spring MVC we should declare a "DispatcherServlet" which is also a front controller, in web.xml.

for both servlets we have different servlet declarations in web.xml.

i.e. for Spring WS I have

  <servlet>
  <servlet-name>springsoap</servlet-name>
  <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
  <servlet-name>springsoap</servlet-name>
  <url-pattern>/soapservices/*</url-pattern>
  </servlet-mapping>

for Spring MVC (RESTful) i have

<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/restservices/*</url-pattern>
    </servlet-mapping>

Therefore i should use 2 config files ?? one named springmvc-servlet.xml and another springsoap-servlet.xml ?

Can this be done ?


回答1:


Yes, this is fine. You put the MVC-related stuff into one, and the WS stuff into another.

If they need to share services, then it's best to declare a shared context using ContextLoaderListener in web.xml, which defines a third context which should contain the shared beans (see docs for example of how to set this up).

It's also worth nothing that MessageDispatcherServlet is just a convenient assembly of a standard DispatcherServlet plus a few other components. You can just declare those components yourself and use a DispatcherServlet, but that gets quite fiddly.




回答2:


You can download an example at https://code.google.com/p/spring-ws-2-0-0-rc2-tutorial/downloads/detail?name=spring-ws.zip&can=2&q=



来源:https://stackoverflow.com/questions/4078795/can-i-use-spring-mvc-and-spring-ws-in-one-single-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!