zoukankan      html  css  js  c++  java
  • 【SpringBoot】ConflictingBeanDefinitionException: Annotation-specified bean name……

    报错日志如下:

    Caused by:org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'globalExceptionHandler' for bean class [com.cheng.cloud.common.exception.handler.GlobalExceptionHandler] conflicts with existing, non-compatible bean definition of same name and class [com.cheng.media.exception.handler.GlobalExceptionHandler]
        at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:345)
        at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:283)
        at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:135)
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287)
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
        ... 21 common frames omitted
    

    通过日志可以看出是因为spring容器初始化同名不同包的类时,不知道加载哪一个,而导致的冲突。

    因此,我们需要解决冲突,在启动类Application中去除一个类。

    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableFeignClients
    @ComponentScan(basePackages = {"com.cheng.media", "com.cheng.cloud"},
            excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {GlobalExceptionHandler.class}))
    public class Application extends WebMvcConfigurerAdapter {
    
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
    }
    
    
    
    ____________________________特此,勉励____________________________
    本文作者cheng2839
    本文链接https://www.cnblogs.com/cheng2839
    关于博主:评论和私信会在第一时间回复。
    版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
    声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
  • 相关阅读:
    Nginx日志定时切割脚本
    阿里大于短信接口
    阿里云Linux系统挂载数据盘
    阿里云 OSS+CDN
    值得一学的几条谷歌搜索技巧
    【转】makefile语法规则
    【转】GCC使用简介
    网络编程中常见地址结构与转换(IPv4/IPv6)
    【转】adns解析库——域名解析实例(C++、linux)
    【转】什么是自动化测试
  • 原文地址:https://www.cnblogs.com/cheng2839/p/13596123.html
Copyright © 2011-2022 走看看