2

私は自分のカスタムライブラリから、gradleを使ってインポートしたBeanをオートワイヤードするのに苦労しています。 私はまだ解決策を見つけることができません似たようなトピックのカップルを読んだ後。Springブート:ライブラリプロジェクトのオートワイヤー豆

私は他のプロジェクト(コンポーネント、リポジトリなどの私のカスタムライブラリ...)に依存するSpringブートプロジェクトを持っています。このライブラリはSpring以外の実行可能なjarで、主にドメインのエンティティとリポジトリから構成されています。実行可能なApplication.classと任意のプロパティがありません...

私がアプリケーションを起動すると、(ライブラリからの)My 'CustomUserService' Beanが初期化しようとしていますが、その中で自動実行されているBean (インターフェースUserRepository)をロードできませんでした...

エラー:

Parameter 0 of constructor in com.myProject.customLibrary.configuration.CustomUserDetailsService required a bean of type 'com.myProject.customLibrary.configuration.UserRepository' that could not be found.

私も、「注文」を設定する(「scanBasePackageClasses」で)明示的にロードするために、パッケージやマーカーでスキャンしてみましたクラス、追加 'EnableJPARepository'アノテーションを追加しますが、何も機能しません。

コード例(名前は簡単にするために変更されたパッケージ)ライブラリーから

package runnableProject.application; 

import runnableProject.application.configuration.ServerConfigurationReference.class 
import com.myProject.customLibrary.SharedReference.class 

//@SpringBootApplication(scanBasePackages = {"com.myProject.customLibrary", "runnableProject.configuration"}) 
//@EnableJpaRepositories("com.myProject.customLibrary") 

@SpringBootApplication(scanBasePackageClasses = {SharedReference.class, ServerConfigurationReference.class}) 
public class MyApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(MyApplication.class, args); 
    } 

} 

クラス:

package com.myProject.customLibrary.configuration; 

import com.myProject.customLibrary.configuration.UserRepository.class; 

@Service 
public class CustomUserDetailsService implements UserDetailsService { 
    private UserRepository userRepository;  

    @Autowired 
    public CustomUserDetailsService(UserRepository userRepository) { 
     this.userRepository = userRepository;  
    } 
... 

package myProject.customLibrary.configuration; 

@Repository 
public interface UserRepository extends CustomRepository<User> { 
    User findByLoginAndStatus(String var1, Status var2); 

    ... 
} 

答えて

5

ちょうど解決策を見つけました。 代わりに別のライブラリからスキャンする基本パッケージを定義する、私はちょうど私のメインMyApplication.classにそれを注釈の全体の束と、このライブラリ内のコンフィギュレーション・クラスを作成し、インポートした:

package runnableProject.application;  

import com.myProject.customLibrary.configuration.SharedConfigurationReference.class 

@SpringBootApplication 
@Import(SharedConfigurationReference.class) 
public class MyApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(MyApplication.class, args); 
    } 

} 


package com.myProject.customLibrary.configuration; 

@Configuration 
@ComponentScan("com.myProject.customLibrary.configuration") 
@EnableJpaRepositories("com.myProject.customLibrary.configuration.repository") 
@EntityScan("com.myProject.customLibrary.configuration.domain") 
public class SharedConfigurationReference { 
} 
+0

あなた自身の答えを受け入れることができます! – alexbt

+0

ええ。システムは私に2日間でそれを可能にする。 – maret

+0

2日以上経過しています。あなたはポイントに値する。あなたの答えは、膨大なWebサイトを検索した後、私の問題を解決しました。 – mvallebr

関連する問題