Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

598
Views
Spring Data REST controller must not use @RequestMapping on class level as this would cause double registration with Spring MVC

Upgrading from Spring Boot 2.5.5 to 2.5.6 triggered errors of this type from my controller tests:

Spring Data REST controller WidgetController$$EnhancerBySpringCGLIB$$9dfdd90c_3 must not use @RequestMapping on class level as this would cause double registration with Spring MVC!

Caused by: java.lang.IllegalStateException: Spring Data REST controller WidgetController$$EnhancerBySpringCGLIB$$9dfdd90c_3 must not use @RequestMapping on class level as this would cause double registration with Spring MVC!
    at org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.isHandler(BasePathAwareHandlerMapping.java:165) ~[spring-data-rest-webmvc-3.5.6.jar:3.5.6]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:265) ~[spring-webmvc-5.3.12.jar:5.3.12]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:225) ~[spring-webmvc-5.3.12.jar:5.3.12]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:213) ~[spring-webmvc-5.3.12.jar:5.3.12]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:206) ~[spring-webmvc-5.3.12.jar:5.3.12]
    at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.restHandlerMapping(RepositoryRestMvcConfiguration.java:690) ~[spring-data-rest-webmvc-3.5.6.jar:3.5.6]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.12.jar:5.3.12]
    ... 88 common frames omitted

The controllers follow this pattern:

@RepositoryRestController
@RequestMapping("/api/widgets")
@RequiredArgsConstructor
public class WidgetController {
    private final @NotNull WidgetHandler widgetHandler;

    @GetMapping
    public ResponseEntity<List<Widget>> widgets() {
        return ResponseEntity.ok().body(widgetHandler./*...*/);
    }

    // ...
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As from stacktrace, the exception is thrown by isHandler method from the BasePathAwareHandlerMapping class.

2.5.5

    protected boolean isHandler(Class<?> beanType) {
        Class<?> type = ProxyUtils.getUserClass(beanType);
        return type.isAnnotationPresent(BasePathAwareController.class);
    }

2.5.6

    protected boolean isHandler(Class<?> beanType) {
    ...
    if (AnnotatedElementUtils.hasAnnotation(type, RequestMapping.class)) {
        throw new IllegalStateException(String.format(AT_REQUEST_MAPPING_ON_TYPE, beanType.getName()));
    }
    ...
}

If you need the functionalities of spring data rest and you want to use @RepositoryRestController, you can use @RequestMapping (or related @GetMapping, @PostMapping, ...) at method level with the full path.

@RepositoryRestController
@RequiredArgsConstructor
public class WidgetController {
    private final @NotNull WidgetHandler widgetHandler;

    @GetMapping("/api/widgets")
    public ResponseEntity<List<Widget>> widgets() {
        return ResponseEntity.ok().body(widgetHandler./*...*/);
    }

// ...

}

over 4 years ago · Santiago Trujillo Report

0

Change @RepositoryRestController to @RestController:

@RestController @RequestMapping("/api/widgets") @RequiredArgsConstructor
public class WidgetController {
    private final @NotNull WidgetHandler widgetHandler;

    @GetMapping
    public ResponseEntity<List<Widget>> widgets() {
        return ResponseEntity.ok().body(widgetHandler./*...*/);
    }

    // ...
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!