SpringBoot项目启动失败报错Annotation-specified bean name ‘xx‘ for bean class [xxx] conflicts with existing

问题描述:项目启动就会报:Annotation-specified bean name ‘xx’ for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]

意思是说注入的bean冲突了

解决方法:首先查找代码中相同类名的类,找一找有没有重复的,如果有的话就改掉;

也有可能是注入的依赖和本地包中的方法冲突了,在报错信息中找到发生冲突的类名,或者整个包都有冲突找包名,然后再启动项的扫描包注解添加配置
@ComponentScan(value = “需要扫描的包名”,[email protected](type = FilterType.REFEX , pattern = “需要排除扫描的包”))

排除扫描某个类则配置
@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.CUSTOM, classes = CustomFilter.class))

public class CustomFilter implements TypeFilter {

private static final String PACKAGE = ".abc.";

@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
    // 可以通过MetadataReader获得各种信息,然后根据自己的需求返回boolean,实例表示包名含有aaa路径的类名将满足筛选条件。
    return metadataReader.getClassMetadata().getClassName().contains(PACKAGE);
}

含有abc路径的类名将被排除不被加入spring容器中

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码

)">
< <上一篇
下一篇>>