1. Problem background
Split springboot into multi module projects (split in different forms)
Split by hierarchy: one item for controller, one item for service, and one item for Dao (mapper).
Split by business: a business module is split into one project (including the controller, service, Dao, etc. of the business)
After the split is completed, start the original application and prompt application failed to start
2. Problem phenomenon
Description:
Field deptService in com.fanzyx.xx.controller.XxxController required a bean of type 'com.fanzyx.xx.service.XxxService' that could not be found.
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.fanzyx.xx.service.XxxService' in your configuration.
3. Cause of problem
If the basic package path for scanning is not configured in the application, it will only be found under the current module
e.g.
@SpringBootApplication()
public class XxxApplication {
public static void main(String[] args) {
SpringApplication.run(XxxApplication.class,args);
}
}
4. Solution
Add the scan base path in the @springbootapplication() annotation
// Multi-module projects need to be configured to scan for base packages, otherwise they will not be able to load entities from other modules
@SpringBootApplication(scanBasePackages = {"com.fanzyx.crane"})
public class XxxApplication {
public static void main(String[] args) {
SpringApplication.run(XxxApplication .class,args);
}
}
Similar Posts:
- SpringBoot+Mybatis-plus multi-module project startup Error: xxxmapper or basemapper cannot be found
- Container Cannot Find bean, Field usersMapper in com.imooc.impl.UserServiceImpl required a bean of type ‘com.imooc.mapper.UsersMapper’ that could not be found.
- Spring cloud uses feignclient to start and report an error
- Solution to the problem of consider defining a bean of type ‘xxx’ in your configuration in spring boot auto injection
- Consider defining a bean of type ‘xxx’ in your configuration. Autowired(required=true)
- SpringBoot Frame: Failed to determine a suitable driver class [How to Solve]
- Two ways to implement Spring Boot’s scanmapper interface class
- This application has no explicit mapping for /error, so you are seeing this as a fallback
- Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- [Problems with the use of internal classes] No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclo