Spring MVC:REST风格的Web服务+ BlazeDS集成可能在同一个Web应用程序中? [英] Spring MVC: RESTful web services + BlazeDS integration possible in the same web application?

查看:171
本文介绍了Spring MVC:REST风格的Web服务+ BlazeDS集成可能在同一个Web应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring MVC Web应用程序,它通过一个控制器类(用@Controller注释)提供了REST风格的Web服务,该类通过@RequestMapping注释将方法映射到特定的请求类型和签名。

我试图通过1)将HttpFlexSession监听器添加到web.xml,2)将flex:message-broker和flex:remoting-destination声明添加到我的Spring应用程序中,从而将BlazeDS服务目标集成到混合中上下文配置文件,以及3)添加一个通用的/WEB-INF/flex/services-config.xml。

上面的BlazeDS集成步骤似乎已经隐藏了我的RESTful web服务,因为看起来请求不再被路由到控制器方法。

甚至有可能这样做,也就是说,有一个Web应用程序1)通过请求映射控制器方法来服务HTTP请求2)服务远程对象方法调用(即从Flex客户端)通过BlazeDS服务?如果是这样,那么谁能告诉我什么可能是我做错了?



感谢您的帮助。



基本上你需要创建两个单独的调度员,每一个都有不同的路径。

 < 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>
<加载启动> 1< /加载启动>
< / servlet>
< servlet>
< name> spring-mvc< / name>
< servlet-class> org.springframework.web.servlet.DispatcherServlet< / servlet-class>
<加载启动> 1< /加载启动>
< / 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>

现在请求 http:// yourapp / app / somewhere 被路由到Spring MVC,并请求 http:// yourapp / messagebroker 通过BlazeDS路由。



另外,你需要把你的spring上下文文件分成三个:


  • 一个常见的上下文(在上面的例子中名为 applicationContext.xml
  • 一个用于Spring MVC(在上面的例子中命名为 spring-mvc-servlet.xml
  • 一个用于Flex(名为

    检查本节 Spring / BlazeDS文档获取更多信息。


    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.

    解决方案

    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.

    这篇关于Spring MVC:REST风格的Web服务+ BlazeDS集成可能在同一个Web应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆