The dependencies of some of the beans in the application context form a cycle

Laurent Maillet :

I'm working on a Spring Boot v1.4.2.RELEASE application with JPA.

I defined repository interfaces and implementations

ARepository

@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);
    }
}

And a service 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
└─────┘

I followed all steps discribed in http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behaviour

Please help !

Laurent

Andrei Pietrusel :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=456565&siteId=1