Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-5757

Externalized request mapping as a 1st class alternative to @RequestMapping

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 3.0.5
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
    • Last commented by a User:
      false

      Description

      While I am not averse to having the controllers use annotation based configuration, I would love to see a functionally equivalent XML based routing configuration, for those who would rather not use it. The current model, IMHO, has the following problems:

      1. URL mapping is scattered all over the place. If I have 15 controllers, with 10 methods each (and note that there's the issue of each method potentially having a completely different URL that it can match), a newbie would have to look at 150 potential places to map a given URL to the controller action it resolves to. Admittedly, having good conventions and oversight will alleviate this problem, but seems too easy to have things go awry.

      2. any changes to the mapping requires a recompile.

      3. The same controller method cannot be mapped to multiple urls (or at least I can't figure out how to do it ), allowing different views to be driven by the same controller.

      4. A somewhat minor thing. There is now way to write a controller w/o Spring dependencies.

      Btw, It would be nice to have mappings that are pattern based, such as, a way to map /somepath/

      {method} to handler SomePathController, method {method}

      .

      http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/

        Issue Links

          Activity

          Hide
          rstoya05-aop Rossen Stoyanchev added a comment - - edited

          Ilya Kazakevich, yes 3.2 will be released very soon.

          I agree with the Dennis Homann's comment the goal is externalized request mappings, be it XML or not. The springmvc-router project is one example of an alternative. The syntax is very short, which is important for 200+ controllers, and the ability to name a route from a view is very compelling.

          Also the ability to externalize or view all request mappings has been available since 3.1. It can be provided in the form of org.springframework.web.servlet.mvc.method.RequestMappingInfo from any source, not just annotations. Projects like springmvc-router and swagger-springmvc are proof of that as they build on this very mechanism.

          The question really is what form of externalized request mappings to provide explicit support for within Spring MVC. Providing an XML namespace like the one David Sledge showed is relatively trivial to create and plug in even today.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - - edited Ilya Kazakevich , yes 3.2 will be released very soon. I agree with the Dennis Homann 's comment the goal is externalized request mappings, be it XML or not. The springmvc-router project is one example of an alternative. The syntax is very short, which is important for 200+ controllers, and the ability to name a route from a view is very compelling. Also the ability to externalize or view all request mappings has been available since 3.1. It can be provided in the form of org.springframework.web.servlet.mvc.method.RequestMappingInfo from any source, not just annotations. Projects like springmvc-router and swagger-springmvc are proof of that as they build on this very mechanism. The question really is what form of externalized request mappings to provide explicit support for within Spring MVC. Providing an XML namespace like the one David Sledge showed is relatively trivial to create and plug in even today.
          Hide
          jirutka Jakub Jirutka added a comment - - edited

          Rossen Stoyanchev,

          well, if it’s so simple to provide an XML namespace config for requests mapping (that’s all what I want… and believe that also many others), why it’s not gonna be in 3.2?

          Sure, each of us can write it yourself… or write very own framework… but why? We need the only one standard namespace, from Spring. Look at Spring Security, there are many specialized namespaces and it’s great.

          I don’t think that XML is the only way either. The springmvc-router looks good, but the standard way in Spring are XML configs, aren’t they? I mean that there should be the XML namespace for that and then we can have something like springmvc-router (and annotations) as an alternative.

          As you wrote, in the case of hundreds controllers, XML is too verbose. Agree. However, in case of some tiny module where I need only few “endpoints”, I would like to have all config in one place along with beans, security etc.

          Show
          jirutka Jakub Jirutka added a comment - - edited Rossen Stoyanchev , well, if it’s so simple to provide an XML namespace config for requests mapping (that’s all what I want… and believe that also many others), why it’s not gonna be in 3.2? Sure, each of us can write it yourself… or write very own framework… but why? We need the only one standard namespace, from Spring. Look at Spring Security, there are many specialized namespaces and it’s great. I don’t think that XML is the only way either. The springmvc-router looks good, but the standard way in Spring are XML configs, aren’t they? I mean that there should be the XML namespace for that and then we can have something like springmvc-router (and annotations) as an alternative. As you wrote, in the case of hundreds controllers, XML is too verbose. Agree. However, in case of some tiny module where I need only few “endpoints”, I would like to have all config in one place along with beans, security etc.
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Jakub Jirutka, point taken. It is simple in terms of we know how it can be plugged in but it would take a number of iterations to design a usable and complete XML namespace. Why is it not in 3.2? We simply didn't get to it. Just look in JIRA and Github to see the amount of work that goes on and is requested all the time. This is why we have a contribution process in place and when you really care about something, you can help move it forward.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Jakub Jirutka , point taken. It is simple in terms of we know how it can be plugged in but it would take a number of iterations to design a usable and complete XML namespace. Why is it not in 3.2? We simply didn't get to it. Just look in JIRA and Github to see the amount of work that goes on and is requested all the time. This is why we have a contribution process in place and when you really care about something, you can help move it forward.
          Show
          abilan Artem Bilan added a comment - Guys! Spring Integration since 3.0 provides the required solution: http://docs.spring.io/spring-integration/docs/3.0.0.BUILD-SNAPSHOT/reference/html/whats-new.html#3.0-request-mapping https://github.com/spring-projects/spring-integration/blob/master/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/Int2312RequestMappingIntegrationTests-context.xml It will be available in the upcoming Spring Integration RC1 Cheers, Artem
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          I am resolving this as "Won't Fix" in recognition of the fact that we won't pursue this option. When @RequestMapping was first introduced we did support a combination of XML mappings routing to the class + method level resolution via annotations. That lead to many practical issues and eventually to the complete re-write of @RequestMapping infrastructure in Spring Framework 3.1 such that request mappings are purely annotation-based and resolved 100% within the HandlerMapping resolving to a specific method. Technically this new infrastructure allows for completely replacing annotations and populating a RequestMappingInfo from any metadata (like XML or other configuration) but that leads to lots of challenges in supporting references to methods in external configuration.

          Spring Framework 5 has a JDK 8+ baseline and supports a new functional, web framework that allows defining request mappings in the form of routing functions (see introduction). Since the handler is a functional interface it allows for the use of method references. While I wouldn't claim that approach fulfills the requirements for this ticket, it does provide an alternative programming model in which fine-grained request mappings can be expressed more naturally without annotations.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - I am resolving this as "Won't Fix" in recognition of the fact that we won't pursue this option. When @RequestMapping was first introduced we did support a combination of XML mappings routing to the class + method level resolution via annotations. That lead to many practical issues and eventually to the complete re-write of @RequestMapping infrastructure in Spring Framework 3.1 such that request mappings are purely annotation-based and resolved 100% within the HandlerMapping resolving to a specific method. Technically this new infrastructure allows for completely replacing annotations and populating a RequestMappingInfo from any metadata (like XML or other configuration) but that leads to lots of challenges in supporting references to methods in external configuration. Spring Framework 5 has a JDK 8+ baseline and supports a new functional, web framework that allows defining request mappings in the form of routing functions ( see introduction ). Since the handler is a functional interface it allows for the use of method references. While I wouldn't claim that approach fulfills the requirements for this ticket, it does provide an alternative programming model in which fine-grained request mappings can be expressed more naturally without annotations.

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              vijayn Vijay Natarajan
              Last updater:
              Rossen Stoyanchev
            • Votes:
              12 Vote for this issue
              Watchers:
              21 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                20 hours, 15 seconds ago