
问题
在创建多模块项目的时候,需要在一个模块中调用其他模块中的bean,但是报如下错误:
Description:
Field redisService in com.dokbok.hgshopping.users.presentation.RegisterController required a bean of type 'com.dokbok.hgshopping.infrastructure.redis.IRedisService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
原因:springbootapplication默认只会扫描当前包名下的所有类,而不同的module就意味着包名不同,导致其他部分的模块下的bean并没有被springboot接管。需要在启动类中指定需要扫描的包名,如下。
@SpringBootApplication(scanBasePackages = {"com.dokbok"})
由于我的包名【com.dokbok】是所有module下包名的基础部分,因些做出上面的配置即可。