title: spring autowiring with unique beans: Spring expected single matching bean but found 2
body: <p>I am trying to autowire some beans (for dependency injection) using Spring for a webapp.  One controller bean contains another bean which in turn holds a hashmap of another set of beans.  For now the map only has one entry.  When i run in tomcat and call the service I get an error saying that the second bean (held in the controller) is not unique </p>
  
  <pre><code>No unique bean of type [com.hp.it.km.search.web.suggestion.SuggestionService] is defined: expected single matching bean but found 2: [suggestionService, SuggestionService]
  </code></pre>
  
  <p>I cannot see where I am defining the bean twice however  am new to Spring and autowiring so I may be missing something fundamental.  Source code for xml and 2 class listed below...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
  &lt;context:component-scan base-package="com.hp.it.km.search.web.suggestion" /&gt;
  &lt;mvc:annotation-driven /&gt;
  &lt;context:annotation-config /&gt;
  
  &lt;bean id="SuggestionController" class="com.hp.it.km.search.web.suggestion.SuggestionController"&gt;
      &lt;property name="service"&gt;
          &lt;ref bean="SuggestionService" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="SuggestionService" class="com.hp.it.km.search.web.suggestion.SuggestionService"&gt;
      &lt;property name="indexSearchers"&gt; 
           &lt;map&gt;
              &lt;entry key="KMSearcher"&gt; &lt;ref bean="KMSearcherBean"&gt;&lt;/ref&gt;&lt;/entry&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="KMSearcherBean" class="com.hp.it.km.search.web.suggestion.SuggestionIndexSearcher"&gt;
        &lt;constructor-arg index="0" value="KMSearcher" /&gt;
        &lt;constructor-arg index="1" value="C://dev//workspace//search-restful-webapp//src//main//resources//indexes//keyword" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>The class asscoaites with the autowired controller and service bean are here...</p>
  
  <pre><code>@Controller
  public class SuggestionController {
  private SuggestionService service;
  
  @Autowired
  public void setService(SuggestionService service) {
      this.service = service;
  }
  
  public SuggestionService getService() {
      return service;
  }
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>@Component
  public class SuggestionService {
  
  private Map&lt;String, IndexSearcher&gt; indexSearchers = new HashMap&lt;String,      IndexSearcher&gt;();
  
  @Autowired
  public void setIndexSearchers(Map&lt;String, IndexSearcher&gt; indexSearchers) {
      this.indexSearchers = indexSearchers;
  }
  
      public SuggestionService() {
      super(); }
  </code></pre>
  
  <p>Please Help!</p>