-
Notifications
You must be signed in to change notification settings - Fork 40.2k
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
Document @SpringBootApplication scanBasePackages restrictions #18109
Comments
I agree that this is a little confusing, although at this point it's hard to see how we can change things without breaking existing code. The main reason it ended up like this is that component scanning isn't directly implement by Spring Boot. We rely on All things considered, I don't think there's much we can do about this now. Any fix is likely to be quite involved and we'd need to add new attributes to Since most users appear to be following our recommended project structure, I think users needing to specify the three annotations ( I'm sorry that it's a bit more verbose than we'd ideally like. |
I think the least that can be done is updating the documentation and pointing this out. Yesterday one of my teammates spent an entire day trying to debug why his repository beans are not being found and injected... 😬 |
Also regarding the project structure: We have a multi module Spring project comprised of these modules (I am using dummy names here):
And we have some aux modules too:
I think a structure like this is probably quite common in multi module projects. And I think it is not a good idea to have all three It is not a big deal in general (we have a meta annotation So this might be worth mentioning in the docs... |
Good points. I've reopened the issue as a documentation enhancement. |
If I write an
Application
class incom.acme.app
and annotate in such a way to drive Spring scan its parent package too:Then if I have my entity and repository classes defined under sibling packages to
com.acme.app
:com.acme.entities
andcom.acme.repos
respectively, they won't be picked up by Spring Boot and in order to make them recognized I have to explicitly use
EntityScan
andEnableJpaRepositories
:I was stepping through the Spring Boot code to see why is this happening and it boils down to
@SpringBootApplication(scanBasePackages = {"com.acme"})
not addingcom.acme
toorg.springframework.boot.autoconfigure.AutoConfigurationPackages.BasePackages#packages
(it will only add the package of theApplication
class,com.acme.app
toBasePackages#packages
).What is the thinking behind this logic? Wouldn't it make sense to make
@SpringBootApplication(scanBasePackages = {"com.acme"})
addcom.acme
toBasePackages#packages
too?The text was updated successfully, but these errors were encountered: