-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Introduce common composed annotations for @RequestMapping [SPR-13992] #18565
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
Comments
Sam Brannen commented Work on this issue is being performed in the following branch: https://github.com/sbrannen/spring-framework/commits/SPR-13992 |
Kazuki Shimizu commented Is not need Thanks. |
Sam Brannen commented Rossen Stoyanchev, please review the pull request: |
Sam Brannen commented Kazuki Shimizu, for 4.3 RC1 the team decided to implement a minimal set of composed annotations for Regards, Sam |
Kazuki Shimizu commented Sam Brannen, Thanks for your comment!
OK! I understand spring team decision. Probably, |
Sébastien Deleuze commented Big +1 for this feature for Spring + Kotlin application developers, it will allow them to write |
Rossen Stoyanchev commented Kazuki Shimizu, for 4.3 we are also adding built-in OPTIONS and HEAD support (see #17721). That means every controller method has those methods covered by Spring MVC. We do allow HEAD and OPTIONS to be mapped explicitly still. However I'm wondering if this changes your mind or do you have use cases in mind still? |
Kazuki Shimizu commented Rossen Stoyanchev, thanks for your comment !! I have missed the #17721. It's very good improvement (y) |
Sam Brannen commented Pushed to |
Phil Webb commented I might be a bit late to the party, but is the @GetMapping("/{username}/vehicle")
public String getVehicle(@PathVariable String username) {
// ...
}
@DeleteMapping("/{username}/vehicle")
public String deleteVehicle(@PathVariable String username) {
// ...
}
@PutMapping("/{username}/vehicle")
public String replaceVehicle(@PathVariable String username) {
// ...
} vs @Get("/{username}/vehicle")
public String getVehicle(@PathVariable String username) {
// ...
}
@Delete("/{username}/vehicle")
public String deleteVehicle(@PathVariable String username) {
// ...
}
@Put("/{username}/vehicle")
public String replaceVehicle(@PathVariable String username) {
// ...
} |
Sam Brannen commented The "Mapping" suffix is not technically necessary, but the team decided against the shorter variants for the following reasons.
For what it's worth, I also prefer Regards, Sam |
Rossen Stoyanchev commented The The exact same line of thought applies to The association with a mental model is all too often underestimated IMO. JAX-RS has a different style of mapping and while the two won't be mixed in the same class, people with all sorts of background and knowledge will come across all sorts of examples across the internet. Having to add explanations on how the two may be the same or not (in order to help readers) is completely undesirable. Furthermore JAX-RS has been around for many years. Those annotations have well established associations and expectations for many. What we are adding here are framework endorsed shortcut annotations that should be consistent with other usages in the framework including Lastly not to forget that you still need |
Oliver Drotbohm commented I'd like to cast another vote on not putting these shortcut annotations into the framework. They cause a lot of confusion, disputes over naming so that we're probably never going to get to a name that pleases everyone, see above and add very little benefit. Assume Jane developer is new to the framework, enthusiastic about these annotation and she uses quite a few of them in her controller implementation. Now she realizes, she needs to restrict based on HTTP header. How does she find out she can actually restrict on those. Okay, she checks the documentation and finds out she needs to use a different annotation. Once she accepted that and wondered why that actually is the case, she now ands up with a mixture of those shortcut annotations and good ol' Another aspect that plays into this: if I can totally see the case for Don't get me wrong, for more experienced users these annotations look like a shortcut but for less experienced ones they're not. The scenario will look like the simply ones don't provide enough mapping functionality so that "other needs to be used in such scenarios". We're basically painting ourselves in a corner of I am all in for the framework being able to work with composed annotations so that people can craft their own shortcuts and even a dedicated library living outside the framework for everyone keen to use to do so. If people want to create their |
Adam Berlin commented I'd like to add a vote for |
Dave Syer commented My $0.02. I like the brevity (and I'm not known for that). If Ollie is right, though, and you need to change annotations in order to add a media type constraint, then I think that's bad. Why can't |
Sam Brannen commented
Glad to hear it. :)
Those are valid questions, and the fact of the matter is that we've gone back and forth on this particular issue. In the Spring Composed project, I actually included all attributes from For Spring Framework 4.3, however, we went a different route. Namely, we decided to only include attributes from
Although the omission of the last two is somewhat debatable, the consensus in the team was that "it's easier to add attributes at a later date than it is to remove them once they are published." This decision is, however, not set in stone. Regards, Sam |
Dave Syer commented OK, so I wasn't missing anything. Don't care personally about "name", but I don't see any reason to force people to use a different annotation if they want header constraints. I guess one point is that people often mistake constraints for method parameters (and don't realize they are imposing a constraint when they add one), but I think I'd rather pay that price and try to do some education, then have to explain why |
Marcel Overdijk commented I would always favour anything that would make However I understand Oliver's concern. |
Enrique Ruiz (DiSiD) commented I agree with Oliver: composed annotations are a good improvement for experienced developers but it makes a bit more complicated to understand for newbies. As Oliver said, Boot exists to simplify the complexity of Spring, so why not place these common composed annotations ( |
Rossen Stoyanchev commented Good point Marcel Overdijk about remaining not opinionated. There is no intent here to create many flavors or other variants in the future. In the same line of thought we shouldn't be opinionated about what is and isn't common. The main intent is to introduce focused variants of I don't think putting these annotations in Boot simplifies matters. If the thinking goes that these annotations are for experienced developers, certainly Boot isn't for advanced developers only. These annotations belong in Spring Framework alongside |
Sam Brannen commented I fully agree with Rossen's most recent comments: we shouldn't be overly opinionated in core Spring, and moving such annotations to Boot doesn't solve anything. Furthermore, I'm in favor of adding the Regards, Sam |
Hans Desmet commented As Dave Syer says, An alias for the params parameter with the name paramConstraints could help |
Sébastien Deleuze commented Rossen Stoyanchev Sam Brannen Also +1 for having |
Sam Brannen commented Since #18544 has been completed, we need to decide on the following proposal:
|
Sam Brannen commented Reopened in order to discuss additional deliverables. |
Sam Brannen commented Based on community feedback and further team discussions, I am once again resolving this issue as Complete. See the following commits for details: In summary, the only composed |
Sam Brannen opened SPR-13992 and commented
Overview
See #18022.
Deliverables
@GetMapping
,@PostMapping
,@PutMapping
,@DeleteMapping
, &@PatchMapping
composed annotations for@RequestMapping
headers
andname
attribute in composed@RequestMapping
annotations.value
,path
,consumes
, andproduces
attributes to singleString
values in composed@RequestMapping
annotations. (see Allow a single element to override an array attribute in a meta-annotation [SPR-13972] #18544)Affects: 4.2 GA
Issue Links:
@RequestMapping
annotations1 votes, 14 watchers
The text was updated successfully, but these errors were encountered: