Bean named 'BService' is expected to be of type 'path1' but was actually of type 'path2'

xiaoxiao2021-02-28  40

报错:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'BService' is expected to be of type 'path1' but was actually of type 'path2'

……

原因是,AService里面用@Resource调用了Bsource,而Bsource在路径1和路径2中均存在。

解决方法是在@Resource注解里加上(name = "xxx"),其中xxx为Bsource的@Service("xxx")名字。这样做可以指定唯一路径,就不会报这个错了。

转载请注明原文地址: https://www.6miu.com/read-78112.html

最新回复(0)