Feature regression : Spring Data REST controller must not use @RequestMapping on class level as this would cause double registration with Spring MVC
See original GitHub issueOn latest version @RequestMapping isn’t more allowed at class level due to this change =>
https://github.com/spring-projects/spring-data-rest/commit/46dc6e03fcd13cadfafeab22ba813c12a8dc9688
@RequestMapping is now only allowed on method level but that isn’t an valid option for method on an abstract controller.
@RepositoryRestController
@RequestMapping("/api/widgets")
public class WidgetController extends BaseControler {
// ...
}
public class BaseControler {
@GetMapping("/get")
public ResponseEntity<String> get() {
return ResponseEntity.ok().body(....);
}
}
Proposition of fix =>
Add a field “path/value” on the annotation @RepositoryRestController to be able to set a root path at class level.
@RepositoryRestController("/api/widgets")
@RequiredArgsConstructor
public class WidgetController extends BaseControler {
// ...
}
public class BaseControler {
@GetMapping("/get")
public ResponseEntity<String> get() {
return ResponseEntity.ok().body(....);
}
}
Stackoverflow discussion => https://stackoverflow.com/questions/69825704/spring-data-rest-controller-must-not-use-requestmapping-on-class-level-as-this
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Spring Data REST controller must not use @RequestMapping ...
Spring Data REST controller must not use @RequestMapping on class level as this would cause double registration with Spring MVC ; @RequestMapping ......
Read more >Spring Data REST controller must not use @RequestMapping ...
[Solved]-Spring Data REST controller must not use @RequestMapping on class level as this would cause double registration with Spring MVC-Spring MVC.
Read more >22. Web MVC framework - Spring
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler ...
Read more >Top 50 Spring Boot Interview Questions and Answers in 2023
This article on Top 50 Spring Boot Interview Questions is a comprehensive guide to the most frequently asked questions in your interviews.
Read more >request method 'post' not supported spring mvc
It should be automatically added by spring boot if it's found on the classpath. Spelling MisMatch ! The consent submitted will only be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It turns out this was already released with 3.7.2 and I just forgot to close the ticket, i.e. this should already be available in the most recent Spring Boot 2.7.
This issue is also blocking us from upgrading to 2.5.6 or later. We do use abstract controllers extensively and we know of no other work-around. Any chance we could get some movement on the associated pull request?