循环依赖Spring Boot

时间:2018-01-16 16:06:07

标签: spring spring-boot spring-data-jpa

我收到错误消息“说明:

应用程序上下文中某些bean的依赖关系形成一个循环:

┌─────┐ | jpaProductsDaoImpl在文件[C:\ W ##### \ Repository_IntelliJ \ A #### \ out \ production \ classes \ pl \ edu \ agh \ bazydanych2017 \ dao \ jpa \ JpaProductsDaoImpl.class]中定义 └─────┘

JpaProductsDaoImpl类

@Repository
public class JpaProductsDaoImpl {

    private final JpaProductsDao jpaProductsDao;

    @Autowired
    public JpaProductsDaoImpl(JpaProductsDao jpaProductsDao) {
        this.jpaProductsDao = jpaProductsDao;
    }

    @PostConstruct
    public void jpaRunAtStart(){
        Products findByName = jpaProductsDao.findByProductname("Chai");
        System.out.println("JPA " + findByName);

        List<Products> sortByProductName = jpaProductsDao.findAll(new Sort(Sort.Direction.ASC, "productname"));
        for (Products products : sortByProductName) {
            System.out.println("JPA Sort " + products);
        }

    }
  • 你能告诉我出了什么问题吗?

0 个答案:

没有答案