2017-01-12 14 views
5

döngüsünü oluşturur. JPA ile bir Spring Boot v1.4.2.RELEASE uygulaması üzerinde çalışıyorum. Bazı fasulyelerin uygulama bağlamındaki bağımlılıkları

IARepositoryImpl

depo arayüzleri ve uygulamaları

ARepository

@Repository 
public interface ARepository extends CrudRepository<A, String>, ARepositoryCustom, JpaSpecificationExecutor<A> { 
} 

ARepositoryCustom

@Repository 
public interface ARepositoryCustom { 
    Page<A> findA(findAForm form, Pageable pageable); 
} 

tanımlandığı

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

Ve bir servis AServiceImpl

@Service 
public class AServiceImpl implements AService { 
    private ARepository aRepository; 
    public AServiceImpl(ARepository aRepository) { 
     super(); 
     this.aRepository = aRepository; 
    } 
    ... 
} 

mesajla başlamaz başvurum:

 
*************************** 
APPLICATION FAILED TO START 
*************************** 

Description: 

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

| aRepositoryImpl 
└─────┘ 

Ben http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behaviour

yardım edin de anlatılanla tüm adımları takip !

Laurent

+2

Eğer sen bir arabirim 'var o uygulama Bahar Verilerle –

+0

ARepositoryCustom' gelen Repository' @ ek açıklama 'kaldırmak için deneyin Arepository 'ArepositoryCustom' uzandığında uygulamada 'Arepository' arayüzünü kullanırsınız. SPring Data'dan şüphe edeceğim şeyler anlamaya yetecek. Ayrıca, bu yöntem hizmetinize aittir ve depoda bulunmaz. – Aeteros

+0

ile üretme yerine var sağlamak istiyoruz çünkü' @ Repository' olarak 'ARepositoryCustom' münasebetiyle gerek yoktur' –

cevap

4

orijinal sorun için basit bir düzeltme var: Sadece ARepositoryCustom gelen ve ARepositoryImpl gelen @Repository kaldırın. Tüm adlandırma ve arabirim/sınıf hiyerarşilerini saklayın. Hepsi iyi.

1

Ben senin kaynak kodu test ve zor bir şey buldum.

There is a circular dependency between 1 beans in the application context: 
- ARepositoryImpl (field private test.ARepository test.ARepositoryImpl.aRepository) 
- aRepositoryImpl 

Sonra ben Bahar 'karıştı' ARepository (JPA depo) ve ARepositoryImpl (Özel depo) arasında tahmin:

Önce, kaynak koduyla, aşağıdaki hatayı aldım. ARepository'u BRepository gibi başka bir şeye atamanızı öneririm. Ders adını değiştirdiğimde işe yaradı. Bahar Verileri (https://docs.spring.io/spring-data/jpa/docs/current/reference/html/) ait offcial belgelerine göre

:

These classes need to follow the naming convention of appending the namespace element’s attribute repository-impl-postfix to the found repository interface name. This postfix defaults to Impl

İlgili konular