Description
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:
- When specified the Non-existent package using @ControllerAdvice(basePackages), has been applied to all controllers. [SPR-12510] #17115 When specified the Non-existent package using
@ControllerAdvice
(basePackages), has been applied to all controllers. ("is duplicated by") - @ControllerAdvice(basePackageClasses) do the prefix search by package name. [SPR-12509] #17114
@ControllerAdvice
(basePackageClasses) do the prefix search by package name.
Referenced from: commits 4013fe0, 1d6978a
Backported to: 4.0.9