Skip to content

URI/URL Related Improvement Suggestions for RequestMapping in Spring MVC [SPR-7585] #12241

Closed
@spring-projects-issues

Description

@spring-projects-issues

Doug Gschwind opened SPR-7585 and commented

The RequestMapping annotation does a great job of helping the reader of a Spring MVC Controller understand which method(s) on that Controller will be invoked given a URI such as "/account", the HTTP method (e.g. GET or POST), as well as given the presence/absence of certain identified HTTP request parameters.

I believe this implementation suffers from the following though, and hence could be improved to address these concerns :

  1. These URIs embedded in a Spring MVC Controller are the source of Don't Repeat Yourself violations since that same URI has to be repeated elsewhere in say a JSP that has a hyperlink or a button that intends to invoke a given method on a given type of Controller when the hyperlink or button is clicked upon.
  2. Spring MVC does not appear to have a facility to be able to generate a URL in say a JSP, that intends to invoke a given method on a given type of Controller. This is closely related to the first item.
  3. By having these URIs sprinkled throughout your Spring MVC Controller classes, you have a little bit of research to do if you plan to introduce a new Controller that should have a distinct URI that it responds to. A text search through the source files would solve that problem, but that is slow and error prone. I understand the Spring MVC plugin for Eclipse has some support for this, but once again requires the human eye to review all the existing URIs to determine if there exists a collision or partial URI match of some sort.

I have tried to solve one and two by placing information in the Spring MVC descriptor, but that involves interrogating the ApplicationContext, and of course, my own custom code. I would like the framework to provide this support for me, so that I have to specify a URI for a Controller and Method, once and only once. If that were possible, I could make a URI change in one place, and the app would continue to run fine (assuming that change introduced no [partial] collisions) without any further effort.

Thank you,

Doug Gschwind


Affects: 3.0 GA

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions