Skip to content

Base packages referenced from @ControllerAdvice must contain at least one Controller [SPR-12506] #17111

Closed
@spring-projects-issues

Description

@spring-projects-issues

Nestor Tarin Burriel opened SPR-12506 and commented

When having a controller package structure like:

  • my.controller
    • server
    • user
    • group
  • my.other.controller
    • role
    • permission

and no controller exists in package my.controller but in sub-packages server, user and group the @ControllerAdvice is applied to all controllers instead of only the ones in package my.controller.

So, for example, following the above package structure if I would like to have two different @ControllerAdvice, one for all controller contained in the package my.controller and another one for the ones contained in my.other.controller I need to add a dummy controller on each package in order to apply the correct advice.

The controller advice documentation points out that you should consider to have such a dummy controller in order to reference it from the advice

Class<?>[ ] basePackageClasses()
Type-safe alternative to value() for specifying the packages to select Controllers to be assisted by the @ControllerAdvice annotated class.
Consider creating a special no-op marker class or interface in each package that serves no purpose other than being referenced by this attribute.

As other usages of the same kind of annotation property (e.g. @ComponentScan.basePackages) I expected not to have such a dummy controller but let the framework find them in the sub packages


Affects: 4.0.6

Issue Links:

Referenced from: commits 4013fe0, 1d6978a

Backported to: 4.0.9

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions