创建名称为“ XXX”的bean时出错:通过字段“ XXX”表示的依赖关系未得到满足

问题描述

@EntityScan("modele")

Test并不是说真的是Spring Bean,而是 JPA Entity@ComponentScan验看@Configuration@Component@Service@Repository@Controller@RestController@EntityScan将寻找实体。

  • Application.java在你的包的根:com.domain.project;
  • 您的存储库在com.domain.project.dao;
  • 您在下的实体com.domain.project.domain

然后,您将不需要@EntityScan@ComponentScan@EnableJpaRepositoriesSpringBoot将仅提取com.domain.project中发现的所有内容。*

解决方法

下面是跟踪:

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“
testController”的bean时出错:通过字段“
testDao”表示的不满意的依赖关系;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为’testDAO’的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:不是托管类型:class
modele.Test

由以下原因引起:org.springframework.beans.factory.BeanCreationException:创建名称为’testDAO’的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:不是托管类型:class
modele.Test

原因:java.lang.IllegalArgumentException:不是托管类型:class modele.Test

根据我的理解,根本的错误是Not a managed type: class modele.Test,与Test不被视为一个实体有什么关系?

这是我的项目:

架构:http//imgur.com/a/2xsI4

应用程序

@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

我将不胜感激。谢谢!

猜你在找的技术问答相关文章

如何检查配对的蓝牙设备是打印机还是扫描仪(Android)
是否允许实体正文进行HTTP DELETE请求?
如何将ZipInputStream转换为InputStream?
java.util.logging Java 8中的变量
PowerMockito.doReturn返回null
Java中的RESTful调用
Swing / Java:如何正确使用getText和setText字符串
特殊字符和重音字符
Android Studio中的ndk.dir错误
错误“找不到主类”