2016-12-31 22 views
0

トレースです:エラー「XXX:不満依存関係がフィールドを通して表現 'の下XXX'

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'testDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDAO': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class modele.Test

...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDAO': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class modele.Test

...

Caused by: java.lang.IllegalArgumentException: Not a managed type: class modele.Test

私の理解から、ルートエラーはNot a managed type: class modele.Testです。これは、テストがエンティティとして認識されないことと関係していますか?ここで

は私のプロジェクトです:

アーキテクチャ:http://imgur.com/a/2xsI4

Application.java

@SpringBootApplication 
@ComponentScan("boot") 
@ComponentScan("dao") 
@ComponentScan("modele") 
@EnableJpaRepositories("dao") 
public class Application { 

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

} 

TestDAO.java

@Transactional 
public interface TestDAO extends CrudRepository<Test, Long > { 

    /** 
    * This method will find an User instance in the database by its email. 
    * Note that this method is not implemented and its working code will be 
    * automagically generated from its signature by Spring Data JPA. 
    */ 
    public Test findByEmail(String email); 

} 

Test.java

@Entity 
@Table(name = "test") 
public class Test { 

    // An autogenerated id (unique for each user in the db) 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private long id; 

    @NotNull 
    private String email; 

    @NotNull 
    private String name; 

    // Public methods 

    public Test() { 
    } 

    public Test(long id) { 
     this.id = id; 
    } 

    public Test(String email, String name) { 
     this.email = email; 
     this.name = name; 
    } 
//setters and getters 

私は、任意の助けをいただければと思います。ありがとう!あなたの現在の設定では

+0

「dao」、「modele」、「boot」の親パッケージにアプリケーションを置くと、最後の4つの注釈は役に立たなくなります。 Spring Bootは自動的にそれに基づいて適切なデフォルトを適用します。 –

+0

はい、私のコードではそうではありませんでした。私は今それを変更しました! – Chuck

答えて

1

は、あなたはそれがJPAエンティティだ、

@EntityScan("modele") 

Testが本当に言うあたりのSpring Beanではありません追加する必要があります。 @ComponentScanは、@Configuration,@Component,@Serviceおよび@Repository,@Controllerおよび@RestControllerを探す。 @EntityScanはエンティティを探します。

あなたはこれを読むことができます:Difference between @EntityScan and @ComponentScan

あなたが移動したい場合は、設定が非常に容易になるだろう:

  • Application.javaをあなたのパッケージのルートに:com.domain.project
  • あなたのリポジトリはcom.domain.project.daoです。
  • あなたのエンティティはcom.domain.project.domainです。

その後、あなたは@EntityScan@ComponentScan@EnableJpaRepositories、SpringBootはちょうどピックアップすべてがcom.domain.projectで見つけますを必要としません。*

+0

ありがとうございました。あなたが説明したようにアーキテクチャが変更されました。 – Chuck

関連する問題