मिला है मैं एक वेबपैप के लिए वसंत का उपयोग करके कुछ सेम (निर्भरता इंजेक्शन के लिए) को स्वचालित करने की कोशिश कर रहा हूं। एक नियंत्रक बीन में एक और बीन होता है जो बदले में बीन्स के दूसरे सेट का हैशपैप रखता है। अभी के लिए मानचित्र में केवल एक प्रविष्टि है। जब मैं बिल्ला में चलाने के लिए और सेवा को कॉल मैं कह रही है कि दूसरे सेम (नियंत्रक में आयोजित) अद्वितीय नहीं हैअद्वितीय बीन्स के साथ वसंत ऑटोवॉयरिंग: वसंत की उम्मीद एकल मिलान बीन लेकिन 2
No unique bean of type [com.hp.it.km.search.web.suggestion.SuggestionService] is defined: expected single matching bean but found 2: [suggestionService, SuggestionService]
मुझे नजर नहीं आता है, जहां मैं सेम को परिभाषित कर रहा हूँ कर सकते हैं दो बार हालांकि वसंत और करने के लिए नया हूँ कोई त्रुटि मिलती है ऑटोवॉयरिंग इसलिए मुझे कुछ मौलिक याद आ रही है। एक्सएमएल और नीचे सूचीबद्ध 2 वर्ग के लिए स्रोत कोड ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.hp.it.km.search.web.suggestion" />
<mvc:annotation-driven />
<context:annotation-config />
<bean id="SuggestionController" class="com.hp.it.km.search.web.suggestion.SuggestionController">
<property name="service">
<ref bean="SuggestionService" />
</property>
</bean>
<bean id="SuggestionService" class="com.hp.it.km.search.web.suggestion.SuggestionService">
<property name="indexSearchers">
<map>
<entry key="KMSearcher"> <ref bean="KMSearcherBean"></ref></entry>
</map>
</property>
</bean>
<bean id="KMSearcherBean" class="com.hp.it.km.search.web.suggestion.SuggestionIndexSearcher">
<constructor-arg index="0" value="KMSearcher" />
<constructor-arg index="1" value="C://dev//workspace//search-restful-webapp//src//main//resources//indexes//keyword" />
</bean>
autowired नियंत्रक और सेवा की फलियों के साथ वर्ग asscoaites यहाँ हैं ...
@Controller
public class SuggestionController {
private SuggestionService service;
@Autowired
public void setService(SuggestionService service) {
this.service = service;
}
public SuggestionService getService() {
return service;
}
और ...
@Component
public class SuggestionService {
private Map<String, IndexSearcher> indexSearchers = new HashMap<String, IndexSearcher>();
@Autowired
public void setIndexSearchers(Map<String, IndexSearcher> indexSearchers) {
this.indexSearchers = indexSearchers;
}
public SuggestionService() {
super(); }
कृपया मदद करें!
शानदार मैं बस सेवा वर्ग से घटक हटा दिया। फिर नियंत्रक को दो बार पंजीकृत होने के बारे में एक त्रुटि मिली और इस समाधान के अनुसार घटक स्कैन को हटाकर इसके आसपास हो गया http://stackoverflow.com/a/4804417/491196 आपकी मदद के लिए धन्यवाद –