7
मैं एक ही कक्षा में परिभाषित के कई सेम है:एनोटेशन के साथ वसंत में नाम से ऑटोवायर कैसे करें?
@Bean
public FieldDescriptor fullSpotField() {
FieldDescriptor ans = new FieldDescriptor("full_spot", String.class);
return ans;
}
@Bean
public FieldDescriptor annotationIdField() {
FieldDescriptor ans = new FieldDescriptor("annotationID", Integer.class);
return ans;
}
फलस्वरूप जब मैं उन्हें
@Autowired
public FieldDescriptor fullSpotField;
@Autowired
public FieldDescriptor annotationIdField;
autowire मैं एक अपवाद
NoUniqueBeanDefinitionException: No qualifying bean of type [...FieldDescriptor] is defined: expected single matching bean but found ...
यह कैसे संभव के रूप में नाम से autowire के लिए मिलता है एक्सएमएल कॉन्फ़िगरेशन में?
मैंने पाया कि '@ Qualifier' सेम निर्माण के तरीकों के पास की आवश्यकता नहीं है, यह करने के लिए पर्याप्त है इस टिप्पणी को '@ Autowired' – Dims
@Dims के साथ जोड़ें, आप सही हैं। यदि बीन निर्माण विधि पर 'क्वालीफायर' निर्दिष्ट नहीं है, तो यह पहले बीन के लिए क्वालीफायर नाम के रूप में विधि नाम पूर्व, "fullSpotField" लेता है। –