Spring项目 多模块,找不到其他模块的bean

时间:2025-04-20 19:31:15

一、背景

模块A的包是.**,模块B的包是.**

模块A引入模块B,但是B的bean找不到。

 (:87) - Exception encountered during context initialization - cancelling refresh attempt: : Error creating bean with name 'redisMsgListener': Injection of resource dependencies failed; nested exception is : No qualifying bean of type 

 

二、原因

模块A的Application在下,那就只能扫描这个包下的bean,引入B模块,包名不一致,所以扫描不到B下的bean

 

三、解决方法

方法一:将模块A的包改成与B一致

方法二:使用@ComponentScan(value=".**")注解,制定扫描路径