Sto provando a scartare alcuni bean (per l'iniezione delle dipendenze) utilizzando Spring per una webapp. Un bean controller contiene un altro bean che a sua volta contiene una hashmap di un altro set di bean. Per ora la mappa ha solo una voce. Quando eseguo in Tomcat e chiamare il servizio di ottengo un errore dicendo che il secondo di fagioli (tenutosi a controllore) non riguardano soloautowiring primaverile con bean univoci: fagiolo corrispondente corrispondente alla primavera ma trovato 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]
non riesco a vedere dove sono la definizione del chicco di due volte però sono nuovo primavera e autowiring in modo che possa mancare qualcosa di fondamentale. Il codice sorgente per XML e 2 classe elencato di seguito ...
<?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>
Le asscoaites classe con il controller autowired e fagioli di servizio sono qui ...
@Controller
public class SuggestionController {
private SuggestionService service;
@Autowired
public void setService(SuggestionService service) {
this.service = service;
}
public SuggestionService getService() {
return service;
}
e ...
@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(); }
Si prega di aiuto!
Brillante Ho semplicemente rimosso il componente dalla classe di servizio. Quindi ho ricevuto un errore sul controller che si registra due volte e ho risolto questo problema rimuovendo la scansione dei componenti come da questa soluzione http://stackoverflow.com/a/4804417/491196 Grazie per il tuo aiuto –