Skip to content

Feature regression : Spring Data REST controller must not use @RequestMapping on class level as this would cause double registration with Spring MVC #2087

@yyvess

Description

@yyvess

On latest version @RequestMapping isn't more allowed at class level due to this change =>

46dc6e0

@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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions