maven多模块启动required a bean of type com.xxx.xxx.service that could not be found.

Description:

Field testService in com.xxx.xxx.api.controller.TestController required a bean of type 'com.xxx.xxx.service.TestService' that could not be found.


Action:

Consider defining a bean of type 'com.xxx.xxx.service.TestService' in your configuration.

1.maven多模块启动类:

@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"com.xxx.xxx.service","com.xxx.xxx.api.controller"})
@SpringBootApplication(scanBasePackages = {"com.xxx.xxx.**"})

2.TestService类加注解@Service

另外,暴力方法:

@Autowired
TestService testService;
改为
TestService testService = new TestService();
但是,这样就不归spring管理了
原文地址:https://www.cnblogs.com/guochunyang2004/p/8710177.html