質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

21416閲覧

Springでbean名が競合してしまいます

rinimaruranran

総合スコア36

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2018/11/07 03:45

前提・実現したいこと

複数のDBからデータを持ってきて分析するページを作成しています。
一つのDBからデータを持ってくることは出来たのですが、複数のDBを作成してApplicationを起動させると「BeanDefinitionStoreException」というエラーが発生します。

調べてみると、同名のファイルがどちらのDBにも存在し、bean名が競合してしまっているようです。

解決策として下記サイトを参考にしているのですが、Controllerを一つしか作っていないため、どう変更を加えれば解決するのかわかりません。
https://qiita.com/sinsengumi/items/655d9f3ff49646dfe61a

どのようにすればエラー解消出来ますでしょうか。
ご教示宜しくお願い致します。

エラーメッセージ

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.SampleApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'fooDaoImpl' for bean class [com.example.sample.repository.sales.FooDaoImpl] conflicts with existing, non-compatible bean definition of same name and class [com.example.sample.repository.operation.FooDaoImpl] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at com.example.SampleApplication.main(SampleApplication.java:13) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE] Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'fooDaoImpl' for bean class [com.example.sample.repository.sales.FooDaoImpl] conflicts with existing, non-compatible bean definition of same name and class [com.example.sample.repository.operation.FooDaoImpl] at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:348) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:286) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:288) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] ... 18 common frames omitted

SampleApplication.java

Java

1package com.example; 2 3 4import org.springframework.boot.SpringApplication; 5import org.springframework.boot.autoconfigure.SpringBootApplication; 6import org.springframework.web.bind.annotation.RestController; 7 8 9@SpringBootApplication(scanBasePackages={"com.example.sample"}) 10@RestController 11public class SampleApplication { 12 public static void main(String[] args) { 13 SpringApplication.run(SampleApplication.class, args); 14 } 15} 16

SampleController.java

Java

1package com.example.sample.controller; 2 3import org.springframework.web.bind.annotation.RequestMapping; 4import org.springframework.stereotype.Controller; 5 6@Controller 7 public class SampleController { 8 @RequestMapping("/") 9 String home() { 10 return "home"; 11 } 12 } 13

フォルダ

現在のフォルダ階層

補足情報(FW/ツールのバージョンなど)

Mac
Spring Boot
Eclipse
Doma

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

エラーメッセージをよくよみなさい。重複は以下

  • com.example.sample.repository.sales.FooDaoImpl
  • com.example.sample.repository.operation.FooDaoImpl

対策

  1. @Component の name 属性を付与するか
  2. @ComponentScan の nameGenerator =に自作ジェネレータークラスを設定しましょう。

投稿2018/11/07 03:54

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

rinimaruranran

2018/11/07 05:14

現在、FooDaoImplというファイルの中にはcomponentの記述はないのですが、こちらのファイルの中に追記するという方法でしょうか。 そうであれば、doma-gen-build.xmlで自動的に作成しているファイルになるので、doma-gen-build.xml内に設定を記述するということでしょうか。
退会済みユーザー

退会済みユーザー

2018/11/07 05:29

派生アノテーションが設定されてるはずですよ
rinimaruranran

2018/11/07 07:10 編集

FooDaoImplファイル内に @org.springframework.stereotype.Repository() という記述がありました。 こちらのカッコ内にname属性を記述する方法をご教示頂いているという認識で良いでしょうか。 こちらのファイルを編集しようとすると、「派生しているファイルですが編集しますか?」という内容のメッセージが表示されてしまいます。 【追記】 警告文をyesにして編集し、@org.springframework.stereotype.Repository(value="sales")と変更を加えたところ、このファイルへのエラーは消えました。(自動生成されている他のファイルでも同様のエラー文が出ているため、ファイルを自動生成する際の記述から改善しないといけないようですが、、) ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問