应用程序上下文中某些Bean的依赖关系形成一个循环 [英] The dependencies of some of the beans in the application context form a cycle
问题描述
我正在使用JPA开发Spring Boot v1.4.2.RELEASE应用程序.
I'm working on a Spring Boot v1.4.2.RELEASE application with JPA.
我定义了存储库接口和实现
I defined repository interfaces and implementations
存储库
@Repository
public interface ARepository extends CrudRepository<A, String>, ARepositoryCustom, JpaSpecificationExecutor<A> {
}
ARepositoryCustom
@Repository
public interface ARepositoryCustom {
Page<A> findA(findAForm form, Pageable pageable);
}
ARepositoryImpl
@Repository
public class ARepositoryImpl implements ARepositoryCustom {
@Autowired
private ARepository aRepository;
@Override
public Page<A> findA(findAForm form, Pageable pageable) {
return aRepository.findAll(
where(ASpecs.codeLike(form.getCode()))
.and(ASpecs.labelLike(form.getLabel()))
.and(ASpecs.isActive()),
pageable);
}
}
还有一项服务 AServiceImpl
@Service
public class AServiceImpl implements AService {
private ARepository aRepository;
public AServiceImpl(ARepository aRepository) {
super();
this.aRepository = aRepository;
}
...
}
我的应用程序不会以以下消息开头:
My application won't start with the message :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
| aRepositoryImpl
└─────┘
我遵循了 http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-行为
请帮助!
洛朗
推荐答案
对于您的原始问题有一个简单的解决方法: 只需从ARepositoryCustom和ARepositoryImpl中删除@Repository. 保留所有命名和接口/类层次结构.都还可以.
There's a simple fix for your original problem: Just remove @Repository from ARepositoryCustom and from ARepositoryImpl. Keep all the naming and interface/class hierarchies. They are all OK.
这篇关于应用程序上下文中某些Bean的依赖关系形成一个循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!