2017-01-12 6 views
5

बनाती है मैं जेपीए के साथ स्प्रिंग बूट v1.4.2.RELEASE एप्लिकेशन पर काम कर रहा हूं।एप्लिकेशन संदर्भ में से कुछ बीन्स की निर्भरता एक चक्र

मैं भंडार इंटरफेस और कार्यान्वयन

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

और एक सेवा AServiceImpl

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

मेरा आवेदन संदेश के साथ शुरू नहीं होगी:

 
*************************** 
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-behaviour

कृपया मदद वर्णित पीछा !

लॉरेंट

+2

से 'ARepositoryCustom' –

+0

एनोटेशन' दूर करने के लिए @ Repository' 'ARepositoryCustom' के रूप में' @ Repository' चिह्नित करने के लिए, क्योंकि आप इसे कार्यान्वयन के बजाय है स्प्रिंग डाटा – Aeteros

+0

के साथ पैदा करने में प्रदान करने के लिए आप एक इंटरफेस 'करना चाहते हैं की जरूरत नहीं है की कोशिश करो एआरपोजिटरी 'जो कार्यान्वयन में अगले' इंटरपोजिटरी कस्टम 'का विस्तार करता है, आप इंटरफ़ेस' एआरपोजिटरी 'का उपयोग करते हैं। मुझे संदेह है कि स्पिंग डेटा जेपीए चीजों को समझने में सक्षम होंगे। यह भी है कि विधि आपकी सेवा में है, न कि आपके भंडार में। –

उत्तर

4

वहाँ अपने मूल समस्या के लिए उन्हें आसानी से ठीक है: बस ARepositoryCustom से और ARepositoryImpl से @Repository को हटा दें। सभी नामकरण और इंटरफेस/वर्ग पदानुक्रम रखें। वे सब ठीक हैं।

1

मैं अपने स्रोत कोड परीक्षण किया है, और कुछ मुश्किल पाया।

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

फिर, मुझे लगता है कि वसंत 'भ्रमित' ARepository (जेपीए भंडार) और ARepositoryImpl (कस्टम भंडार) के बीच:

पहले, अपने स्रोत कोड के साथ, मैं निम्नलिखित त्रुटि मिली। तो, मैं आपको का सुझाव दूंगाARepository कुछ और, जैसे कि BRepository। अगर मैंने वर्ग का नाम बदल दिया तो यह काम करता था।

स्प्रिंग डाटा (https://docs.spring.io/spring-data/jpa/docs/current/reference/html/) की offcial प्रलेखन के अनुसार:

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

संबंधित मुद्दे