spring-bootアプリケーションのspring 4.3.0を使用するライブラリを作成しています。このライブラリを消費します。私はライブラリ内の構成クラスを作成し、構成内の@ComponentScanを宣言しているのですが、現在、私は@ ComponentScanをSpringブートアプリケーションのメインクラスで使用しています。代わりに、ライブラリ内のBeanをスキャンします。ファイル。自動構成のスプリングライブラリをスプリングブートアプリケーションに作成する
春ブートアプリケーションでライブラリを消費した後、それが
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sample.book.client.service.BookService] found for dependency [com.sample.book.client.service.BookService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1406)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
... 33 common frames omitted
はどのようにこのエラーを解決するには、ライブラリ内の豆をスキャンし、スローされていませんか?なぜSpringが@Configurationの前に@Serviceクラスをスキャンするのですか?
あなたの助けが必要です。私は必要に応じてコードサンプルを提供します。
私の春のブートアプリケーションがすでにSpringBootApplicationあなたは私のライブラリは春ブーツはないので、スプリングを使用している、「META-INF/spring.factories」を指定したredundant.Alsoだろう宣言ので、再び@SpringBootApplicationと注釈されていますどのように私は、次のインポート "org.springframework.boot.autoconfigure.EnableAutoConfiguration"で自動構成を指定できますか? "EnableAutoConfiguration"はスプリングブートで提供されています。私が間違っている場合は、私に修正してください。 – VelNaga
あなたは、アプリケーションが既に@ SpringBootApplicationである場合、自動設定を有効にしています。次に、META-INF/spring-factoriesをライブラリJARの中に置くか、ライブラリの設定をインポートすることができます。 –
これは動作します。ありがとう。私はMETA-INF/spring.factoriesメソッドに従っていますが、それは魅力的ですが、@Importを定義してくださいか、「@Import」についてのリンクを共有できますか? – VelNaga