我正在使用 JPA 开发 Spring Boot v1.4.2.RELEASE 应用程序。
我定义了存储库接口和实现
储存库
@Repository
public interface ARepository extends CrudRepository<A, String>, ARepositoryCustom, JpaSpecificationExecutor<A> {
}
ARepository自定义
@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;
}
...
}
我的应用程序不会以消息开头:
******************************
应用程序启动失败
******************************
描述:
application context中的一些bean的依赖关系形成了一个循环:
|存储库实现
└──────┘
我遵循了 http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behaviour 中描述的所有步骤
请帮忙 !
洛朗
原文由 Laurent Maillet 发布,翻译遵循 CC BY-SA 4.0 许可协议
对于您的原始问题,有一个简单的修复方法:只需从 ARepositoryCustom 和 ARepositoryImpl 中删除 @Repository。保留所有命名和接口/类层次结构。他们都很好。