title: Spring Mongo Template error while creating bean
body: <p>I am using two databases so I added both in My context servlet. But it gives error..
  My servlet.context is</p>
  
  <pre><code>&lt;!-- Mongo settings --&gt;
      &lt;mongo:mongo id="mongo" host="192.148.5.5" port="27017" /&gt;
  
      &lt;beans:bean id="mongoTemplate"
          class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;beans:constructor-arg ref="mongo" /&gt;
          &lt;beans:constructor-arg name="databaseName"
              value="WriteDB" /&gt;
  
      &lt;/beans:bean&gt;
      &lt;beans:bean id="mongoTemplate2"
          class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;beans:constructor-arg ref="mongo" /&gt;
          &lt;beans:constructor-arg name="databaseName"
              value="readDB" /&gt;
  
      &lt;/beans:bean&gt;
      &lt;mongo:repositories base-package="com.cheasyy.cofinding,com.cheasyy.cofinding.controller" /&gt;
  </code></pre>
  
  <p>Error is</p>
  
  <p>Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.data.mongodb.core.MongoTemplate com.cheasyy.cofinding.service.profile.ProfileServiceImpl.mt; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.data.mongodb.core.MongoTemplate] is defined: expected single matching bean but found 2: [mongoTemplate, mongoTemplate2]
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
  Where I am missing?</p>
  
  <p>My ProfileServiceImpl class is
  @Service</p>
  
  <pre><code>public class ProfileServiceImpl implements profileService {
  
      @Autowired
      MongoTemplate mt;
      @Override
      public void insert(Profile profile) {
          // TODO Auto-generated method stub
          System.out.println("in service ipl");
      mt.save(profile);   
      System.out.println("saved in db");
  
      }
  
  }
  </code></pre>