运行项目,启动报错如下:
at com.meituan.baobab.wtaccess.Application.main(Application.java:51) [classes/:?]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseDataManagerImpl':
Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'damServiceAdapter' is expected to be of type 'com.meituan.baobab.wtaccess.adapter.dam.api.DamServiceAdapter'
but was actually of type 'com.meituan.baobab.commons.filter.adapter.DefaultDamServiceAdapter'
报错提示bean装配成了另外一个。
在import中查看,导入的是com.meituan.baobab.wtaccess.adapter.dam.api.DamServiceAdapter。应该没有问题。
试着删掉它,可以看到有两个包都存在DamServiceAdapter类

而在代码里是使用@Resource注解,而Resource是通过名字装配的,
所以当有两个类名相同会有冲突。导致装配错误。
解决办法:
修改类名或者使用@Autowire
拓展:
@Autowired 与@Resource的区别

在启动项目时遇到Bean自动装配错误,报错显示装配了错误的类。问题源于存在两个相同类名的 DamServiceAdapter 类,导致@Resource 注解因名称匹配出现冲突。解决方案包括修改类名或改用 @Autowired 注解以避免名称依赖。
2022

被折叠的 条评论
为什么被折叠?



