下面是跟蹤:錯誤創建名稱爲豆「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
,這與測試未被識別爲實體有關嗎?
這裏是我的項目:
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
我會很感激的任何幫助。謝謝!
請注意,如果將應用程序放在「dao」,「modele」和「boot」的父包中,那麼這4個最後的註釋是無用的。 Spring Boot將基於此自動應用合理的默認值。 –
是的,但我的代碼並非如此。儘管我現在已經改變了! – Chuck