Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Dec 4, 2014 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 4, 2014

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This issue is caused by ControllerAdviceBean's implementation relying on java.lang.Package which the JVM unfortunately only resolves for non-empty packages. I've revised this towards package name handling, analogous to our regular component scanning, which should be able to handle any package arrangements now.

This will be available in the next 4.1.3 snapshot and backported to 4.0.9 tomorrow (and then available in a 4.0.9 snapshot as well). Please give it an early try...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Nestor Tarin Burriel commented

I've tested with the latest SNAPSHOT (4.0.9.BUILD-SNAPSHOT) and I cannot reproduce the issue any more.

Thanks a lot for the explanation and for fixing it so fast!

Nestor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants