question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

On 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
odrotbohmcommented, Sep 20, 2022

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.

1reaction
terje2001commented, Jan 24, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found