title: MongoTemplate instance is not created inside spring
body: <p>I want to try spring integration with MongoDB, For this purpose I did following things. but its not working Some how MongoTemplate instance is not created and throws java.lang.NullPointerException.
  here is my application-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         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"&gt;
  
    &lt;!-- Activate annotation configured components --&gt;
    &lt;context:annotation-config/&gt;
  
    &lt;!-- Scan components for annotations within the configured package --&gt;
    &lt;context:component-scan base-package="com.jeroenreijn.mongodb.example"&gt;
      &lt;context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/&gt;
    &lt;/context:component-scan&gt;
  
    &lt;!-- Factory bean that creates the Mongo instance --&gt;
    &lt;bean id="mongo" class="com.mongodb.Mongo"&gt;
      &lt;constructor-arg name="host" value="127.0.0.1" /&gt;
      &lt;constructor-arg name="port" value="27017" /&gt;
    &lt;/bean&gt;
  
    &lt;!-- Define the MongoTemplate which handles connectivity with MongoDB --&gt;
    &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate" depends-on="mongo"&gt;
      &lt;constructor-arg name="mongo" ref="mongo"/&gt;
      &lt;constructor-arg name="databaseName" value="firstMongoDB"/&gt;
    &lt;/bean&gt;
  
    &lt;!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes --&gt;
    &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>here is my main method : </p>
  
  <pre><code>public class MainApplication {
  
      /**
       * This is a variable used for Logging purpose, I have used slf4j.
       */
      final Logger LOGGER = LoggerFactory.getLogger(MainApplication.class);
      @Autowired
      MongoTemplate mongoTemplate;
  
      public void savePerson(Person p) {
          mongoTemplate.save(p);
      }
  
      public static void main(String[] args) {
          Person p = new PersonImpl("1", "Ayushya", "Devmurari");
          MainApplication ma = new MainApplication();
          ma.savePerson(p);
          ma.LOGGER.info("Person named : " + p.getName() + " with id : "
                  + p.getId() + " is saved.");
      }
  
  }
  </code></pre>
  
  <p>Here is my model class : </p>
  
  <pre><code>@Document(collection = "AnotherPersonCollection")
  public class PersonImpl implements Person {
  
      private String id;
      private String name;
      private String surname;
  
      // Constructor
      public PersonImpl() {
  
      }
  
      public PersonImpl(String id, String name, String surname) {
          this.id = id;
          this.name = name;
          this.surname = surname;
      }
  
      @Override
      public String getId() {
          return id;
      }
  
      @Override
      public void setId(String id) {
          this.id = id;
      }
  
      @Override
      public String getName() {
          return name;
      }
  
      @Override
      public void setName(String name) {
          this.name = name;
      }
  
      @Override
      public String getSurname() {
          return surname;
      }
  
      @Override
      public void setSurname(String surname) {
          this.surname = surname;
      }
  
      @Override
      public String toString() {
          return "Person has name " + "Id :" + id + "\n" + name + " \n"
                  + "surname :" + surname;
      }
  
  }
  </code></pre>
  
  <p>Need assistance I have tried several tutorials, like mkyong and many others and I have faced NoBeanDefinitionFound for "mongoTemplate" error: so I tried this.</p>
  
  <p>UPDATE: here is my pom.xml</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.discusit&lt;/groupId&gt;
      &lt;artifactId&gt;MongoDBAppTrail4&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;name&gt;Trying to create MongoDBApp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;dependencies&gt;
          &lt;!-- Log4J --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
              &lt;version&gt;1.7.5&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Spring framework --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;3.2.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;3.2.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Spring Web --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;3.2.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- mongodb java driver --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
              &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
              &lt;version&gt;2.11.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Spring data mongodb --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-mongodb&lt;/artifactId&gt;
              &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;cglib&lt;/groupId&gt;
              &lt;artifactId&gt;cglib&lt;/artifactId&gt;
              &lt;version&gt;2.2.2&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.0&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.9&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;downloadSources&gt;true&lt;/downloadSources&gt;
                      &lt;downloadJavadocs&gt;true&lt;/downloadJavadocs&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is my stacktrace : </p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mongoTemplate' is defined
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1102)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
      at com.discusit.main.MainApplication.main(MainApplication.java:39)
  </code></pre>