Spring MVC: RESTful web services + BlazeDS integration possible in the same web application?

一个人想着一个人 提交于 2020-01-14 14:05:46

问题


I have a Spring MVC web application which provides RESTful web services via a controller class (annotated with @Controller) which has methods mapped to specific request types and signatures via @RequestMapping annotations.

I have attempted to integrate a BlazeDS service destination into the mix by 1) adding the HttpFlexSession listener to the web.xml, 2) adding the flex:message-broker and flex:remoting-destination declarations to my Spring application context configuration file, and 3) adding a generic /WEB-INF/flex/services-config.xml.

The above BlazeDS integration steps appear to have hosed my RESTful web services, in that it appears that requests are no longer being routed to the controller methods.

Is it even possible to do this, i.e, to have a single web application which 1) services HTTP requests via request mapped controller methods and 2) services remote object method calls (i.e. from a Flex client) via a BlazeDS service? If so then can anyone tell me what it may be that I'm doing wrong?

Thanks in advance for your help.


回答1:


Yes, it's possible, but it requires a little extra configuration.

Essentially you need to create two seperate dispatchers, each with a different path.

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
    <name>flex</name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <name>spring-mvc</name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>flex</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
 </servlet-mapping>
<servlet-mapping>
    <servlet-name>spring-mvc</servlet-name>
    <url-pattern>/app/*</url-pattern>
 </servlet-mapping>

Now requests to http://yourapp/app/somewhere are routed to Spring MVC, and requests to http://yourapp/messagebroker are routed through BlazeDS.

Also, you'll need to split out your spring context files into three:

  • A common context (named applicationContext.xml in the above example)
  • One for Spring MVC (named spring-mvc-servlet.xml in the above example)
  • One for Flex (named flex-servlet.xml in the above example)

Check out this section from the Spring/BlazeDS docs for more info.



来源:https://stackoverflow.com/questions/4053388/spring-mvc-restful-web-services-blazeds-integration-possible-in-the-same-web

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