title: Spring data mongo db version compatibility with spring
body: <p>Here is my pom.xml</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
      &lt;version&gt;5.0.0.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;5.0.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
      &lt;version&gt;5.0.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
      &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
      &lt;version&gt;3.5.0&lt;/version&gt;
  &lt;/dependency&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;2.0.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is my Bean configurations</p>
  
  <pre><code>&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"
  xmlns:mongo="http://www.springframework.org/schema/data/mongo"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/data/mongo
        http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-4.1.xsd
        http://www.springframework.org/schema/task 
        http://www.springframework.org/schema/task/spring-task-4.0.xsd"&gt;
  
  &lt;mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}"/&gt; 
  &lt;mongo:db-factory id="mongoDbFactory" dbname="${mongo.dbname}" username="${mongo.username}" password="${mongo.password}" mongo-ref="mongo"/&gt;
  
  &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt; 
      &lt;constructor-arg ref="mongoDbFactory"/&gt; 
  &lt;/bean&gt;
  
  &lt;bean id="awayLogDao" class="com.zymr.mongo.repository.AwayLogDao"&gt;
      &lt;constructor-arg ref="mongoTemplate"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>When I try to run my project, I get following exceptions</p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class 
  org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionParser for element [mongo]
  Offending resource: class path resource [conf/spring/ApplicationContext.xml]
  at org.springframework.beans.factory.parsing.FailFastProblemReporter.fatal(FailFastProblemReporter.java:62)
  at org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:90)
  at org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:68)
  at org.springframework.beans.factory.xml.NamespaceHandlerSupport.findParserForElement(NamespaceHandlerSupport.java:86)
  at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1366)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1352)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:178)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:148)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:98)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:223)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:194)
  at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
  at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
  at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
  at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:620)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745)
  
  
  
  java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
  at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:176)
  at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1035)
  at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1011)
  at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:963)
  at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:525)
  at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:112)
  at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)
  at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)
  at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I tried changing versions of spring and spring data mongodb.
  I Used <strong>spring version - 3.2.2.RELEASE</strong> instead of 5.0.0.RELEASE and 
  <strong>spring data mongodb version - 1.2.0.RELEASE</strong> . After using older versions, everything was working fine. But I want to use latest version of spring data mongodb as it supports aggregation operation.</p>
  
  <p>I want to execute following query with spring data mongodb:</p>
  
  <pre><code>db.mycollection.aggregate([
      { "$redact": { 
          "$cond": [ 
              { "$and": [ 
                  { "$eq": [ { "$year": "$date" }, 2017 ] }, 
                  { "$eq": [ { "$month": "$date" }, 10 ] }
              ] }, 
              "$$KEEP", 
              "$$PRUNE" 
          ] } 
      }
  ]) 
  </code></pre>
  
  <p>How can I achieve it? Which version of spring I need to use with latest spring data mongodb?</p>