New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Externalized request mapping as a 1st class alternative to @RequestMapping [SPR-5757] #10427
Comments
Arjen Poutsma commented Since you copy-pasted this issue from a comment on my blog post, it seems appropriate to copy-paste my answer here :): Ad 1 & 2: Rossen wrote a post about combining XML and annotations a while ago. They key idea is to use XML for the course-grainined mappings, and annotations for further disambiguation. Check it out! Ad 3:The Ad 4: It was never possible to write a controller for MVC without having Spring dependencies. Previously, you had to implement the controller interface, or extend from one of the base classes. I would say that the Spring dependency has become less with |
Vijay Natarajan commented :-) It turns out it's not sufficient that I look at the post for comments every day, I apparently also have to refresh the page from the server once in a while!!! Who'd have thunk? :-D Anyway, sorry about that and thanks for the response. Ad 1 & 2: I read Rossen's post, and it was good to see the information there. However, those features address neither problems I pointed. Ad 3: Oh, cool! But could you consider this feature "It would be nice to have mappings that are pattern based, such as, a way to map /somepath/{method} to handler SomePathController, method {method}" ie. a single RequestMapping at say the class level which let's me specify that a portion of the uri maps to a method name. Ad 4. Sure, agreed. I think those improvements are fantastic. However, given that we can pretty much configure everything with annotations, I'd submit that having equivalent XML would eliminate even the compile time dependency. (Note: This is not causing me any trouble at all, as I don't care about not having spring dependencies. Why should I? :) But reduced coupling is always better, no? ) Vijay |
David Sledge commented I'd, also, like to see a third XML-based option for defining controllers with the same level of configuration detail as the annotations. Take the the EditPetForm class referenced in 13.11. Annotation-based controller configuration for instance. Strip out the annotations, and I'd imagine that the XML configuration I would look something like the following:
To reiterate what was said previously, this would help decouple the application from the framework. Ideally, I'd like to reduce number of |
Blurbee commented I totally agree with David. The annotation and XML based configuration must have feature parity. Vijay brought up a very critical point that I would like to keep all my mapping in one file. I just ran into while evaluating spring framework for my project. In fact it is mentioned as a drawback of annotations in the documentation. For users who have already gone down the path of RequestMapping, they should be able to refactor the base URL as a parameter: |
Ilya Kazakevich commented I believe that everything you can do using annotations you also should be able to do using XML. Imagine yourself a really huge project with 200 controllers. Do you want your mappings to be spread across them? Param-to-property mapping (as they have in struts) could be nice too, but in such case controller has to be request-scoped, not singleton. |
Rossen Stoyanchev commented Something that isn't going to address this issue but is worth knowing is the ability to see all request mappings in the STS |
Rossen Stoyanchev commented We can consider this for 3.2. In the mean time, for anyone interested it should be fairly simple to build a |
Rossen Stoyanchev commented Spring Social could benefit from same way of externalizing request mapping configuration. It has a ConnectController, which is mapped to "/connect". Applications using Spring Social may wish to customize or override the URL in its class-level |
Rossen Stoyanchev commented Modified title (was: "XML Based Request mapping with path variables") to reflect more accurately what is being requested vs how it will be implemented.. |
Dennis Homann commented The ability to externalize the request mapping would be of great benefit. Externalization should be the focus, not necessarily the definition of mappings in XML. For instance, if the framework separated the mapping configuration from its execution and provide a convenience configuration builder to be used from XML, we could then just roll our own mapping configurators as needed. |
Rossen Stoyanchev commented I've created #14568 to track the case of customized |
Ilya Kazakevich commented Hello Rossen, I use Intellij IDEA which is pretty popular Java IDE:) It does not have "show all request mapping" feature afaik. And if I write my own xml-based RequestMappingHandlerMapping it would not be supported by Idea too. Idea helps me to write struts.xml, but it would not help me with my custom xml. No static checking. |
Jakub Jirutka commented Yeah, absolutely! I like Spring a lot for its great XML-based configuration support. Why we still cannot configure request mappings in XML? :( |
Ilya Kazakevich commented Moving it to "General backlog" means you would not implement it in 3.2 version?:( |
Rossen Stoyanchev commented 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 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. |
Jakub Jirutka commented 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. |
Rossen Stoyanchev commented 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. |
Artem Bilan commented Guys! Spring Integration since 3.0 provides the required solution: Cheers, |
Rossen Stoyanchev commented I am resolving this as "Won't Fix" in recognition of the fact that we won't pursue this option. When 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. |
Vijay Natarajan opened SPR-5757 and commented
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:
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.
any changes to the mapping requires a recompile.
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.
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/
Affects: 3.0.5
Attachments:
Issue Links:
@Controller
methods from views without hardcoding URLs@PathVariable
based handler methods fail with ambiguity when URL mapping is specified in XML ("supersedes")12 votes, 21 watchers
The text was updated successfully, but these errors were encountered: