about issues that springboot beans cannot inject (related to package location) Change the automatically scanned package

Source: Internet
Author: User

cause : When a colleague writes a demo, The Bean has a @component and cannot be scanned by spring (the idea will not be able to get the corresponding bean at compile time).
Later, the research was related to the location of the document package.

Springboot Bean Assembly Rules:
Scan from top to bottom according to the package location where the application class is located!
"Application class" refers to the project entry class for Springboot. The location of this class is critical:
If the package for the application class is: Then the location of the io.github.gefangshuai.app scan is: The io.github.gefangshuai.app package and all of its sub-packages. If the bean that needs to be injected is not io.github.gefangshuai.app under the package and its child package, it will not be scanned.

Note: You can specify a scanned package by adding @componentscan (basepackages={"xxx.xxx", "xxx.xxx"}) to the application class, but the package will not be scanned under the application class by default once it is specified.

about issues that springboot beans cannot inject (related to package location) Change the automatically scanned package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.