spring-boot で application 起動時に、以下のエラーが発生しました。
対処方法を記載します。

  • エラー内容
    Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'listCommand' for bean class [xyz.monotalk.google.webmaster.cli.subcommands.sites.ListCommand] conflicts with existing, non-compatible bean definition of same name and class [xyz.monotalk.google.webmaster.cli.subcommands.sitemaps.ListCommand]
            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)
    

エラーの原因

Comportnent scan 対象のパッケージ配下に、パッケージ違いで同一のクラス名が存在する場合、bean 登録時に bean 名が重複してしまうようです。


対処方法

以下の記事に、まさに対応方法の記載がありました。
Spring の component-scan で設定される Bean 名をカスタマイズする - Qiita

記事記載のFQCNBeanNameGenerator作成し、完全修飾クラス名を bean 名とすることで対処しました。

以上です。

コメント