0

Below is the trace :

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

From my understanding the root error is Not a managed type: class modele.Test, which would have something to do with Test not being recognized as an entity ?

Here's my project :

Architecture : https://i.stack.imgur.com/xcYVi.jpg

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

I'd appreciate any help. Thanks!

Narm
  • 10,677
  • 5
  • 41
  • 54
Chuck
  • 351
  • 1
  • 6
  • 20
  • As a side note, those 4 last annotations are useless if you put your application in a parent package of "dao", "modele" and "boot". Spring Boot will automatically apply sensible defaults based on that. – Stephane Nicoll Dec 31 '16 at 17:11
  • Yes but that was not the case in my code. I now have changed that though! – Chuck Dec 31 '16 at 17:59

1 Answers1

3

With your current setup, you need to add

@EntityScan("modele")

Test isn't really a Spring Bean per say, it's a JPA Entity. @ComponentScan looks for @Configuration, @Component, @Service and @Repository, @Controller and @RestController. @EntityScan will look for Entities.

You can read this: Difference between @EntityScan and @ComponentScan

Your configuration would be much easier if you'd move :

  • Application.java at the root of your packages: com.domain.project;
  • your repositories under com.domain.project.dao;
  • your entities under com.domain.project.domain.

Then, you wouldn't need @EntityScan, @ComponentScan and @EnableJpaRepositories, SpringBoot will just pickup everything found in com.domain.project.*

Community
  • 1
  • 1
alexbt
  • 16,415
  • 6
  • 78
  • 87