1

I did not know how to turn the title, hope this is understandable. I am working on a web-app that have existed for years and is currently in production. This web-app uses spring-flex to display some views and one of the dependency of spring-flex is spring-mvc. I think a relevant link would be there.

So I have all the dependencies already configured in my pom, and a DispatcherServlet already configured in my web.xml with the exact configuration from the manual (I am not the one who did the integration, I am trying to figuring out how it was done).

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

<servlet-mapping>
    <servlet-name>flex_servlet</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>

From the link I have provided, we can see that by default when a flex message-broker is configured, the configuration looks like this (although it is nowhere to be seen in the project)

<!-- Maps request paths at /* to the BlazeDS MessageBroker -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /*=_messageBroker
        </value>
    </property>
</bean>

<!-- Dispatches requests mapped to a MessageBroker -->
<bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter"/>    

Now that I want to use spring-mvc for other tasks, what should I do?

  • Declare another DispatcherServlet or use the same one?
  • And If I use the same one, can I just copy-past the above block and complete it to override the default configuration?
  • And if I don't use the same one, how will each DispatcherServlet know which HandlerMapping to use since they are supposed to discover it themselves?

thanks for your help

EDIT: for future reference, here are relevant documentations:

Aldian
  • 2,592
  • 2
  • 27
  • 39
  • I don't know why but my `Hi!` at the top won't display – Aldian Jul 07 '14 at 15:54
  • 1
    You are lucky your `thanks for your help` is still there. See [here](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – Alexey Jul 08 '14 at 01:27

1 Answers1

2

With BlazeDS you define a named service, the DispatcherServlet will use this name to send requests to the proper service. So to answer your questions:

  • Declare another DispatcherServlet or use the same one? Use the same one
  • And If I use the same one, can I just copy-past the above block and complete it to override the default configuration? No change needed
  • And if I don't use the same one, how will each DispatcherServlet know which HandlerMapping to use since they are supposed to discover it themselves? Irrelevant, you use the same one

Based on our conversation below, the answer from this question might help you aswell: Spring MVC: RESTful web services + BlazeDS integration possible in the same web application?

Community
  • 1
  • 1
  • Sorry but I finally managed to find the relevant doc and they recommend using two separated DispatcherServlet, although using the same one stay possible http://docs.spring.io/spring-flex/docs/1.5.x/reference/html/index.html#flex-and-spring-mvc – Aldian Jul 08 '14 at 08:53
  • Your question mentions nothing about using multiple client types. – Robin van den Bogaard Jul 08 '14 at 08:56
  • Sorry for being unclear. Currently flex works well. `/messagebroker/*` patterns are served as intended. But I want to set up some controllers of my own on `/springmvc/*` and my question is about how to do that while keeping the other working – Aldian Jul 08 '14 at 09:00
  • The answer to this question can help you as-well if the docs aren't enough: http://stackoverflow.com/questions/4053388/spring-mvc-restful-web-services-blazeds-integration-possible-in-the-same-web?rq=1 I'll update my answer aswell – Robin van den Bogaard Jul 08 '14 at 09:05
  • Yes this is what I am looking for. But I also need to define an handlerMapping since I want all `/springmvc/*.json` request be handled by the same bean. Relevant documentation is here:http://docs.spring.io/spring-framework/docs/2.5.3/reference/mvc.html#mvc-handlermapping-urlhandlermapping But they say that "HandlerMapping beans are automatically detected by the DispatcherServlet" This is why I was wondering how it works in case there are several DispatcherServlet for each one to understand which mappings affects him? – Aldian Jul 08 '14 at 09:14
  • Ok I have found out. This is due to me being inexperimented with spring. When you declare a servlet named springmvc, it will search for configuration in [/WEB-INF/springmvc-servlet.xml]. If I declare a mapping there, it will be specific to this servlet. Thanks for your help – Aldian Jul 08 '14 at 09:40