title: Getting java.lang.NoSuchFieldError: INSTANCE while creating mongoTemplate bean in spring
body: <p>Getting below error while creating mongoTemplate bean.</p>
  
  <p>I think jar versions are conflicting.</p>
  
  <p>If I am using spring-data-mongodb 1.2.0.RELEASE then it showing java.lang.NOCLASSDEFMETHOD error.</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
            org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278)
            org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
            org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
            org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
            org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
            org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
            org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
            org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
            org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
            org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
            org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
            org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
            org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
            org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
            org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
            org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
            org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
            org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
            javax.servlet.GenericServlet.init(GenericServlet.java:158)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
            org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
            org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
            org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
            org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            java.lang.Thread.run(Thread.java:745)
        
                <p>
                    <b>root cause</b>
                </p>
              <pre>org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
          org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164)
          org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125)
          org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:270)
          org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
          org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
          org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
          org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
          org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
          org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
          org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
          org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
          org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
          org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
          org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
          org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
          org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
          org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
          org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
          org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
          org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
          javax.servlet.GenericServlet.init(GenericServlet.java:158)
          org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
          org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
          org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
          org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
          org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
          org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
          org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
          org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
          java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
          java.lang.Thread.run(Thread.java:745)
      </pre></p>
  </blockquote>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
      xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.websystique.springmvc&lt;/groupId&gt;
      &lt;artifactId&gt;JioAsp&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;name&gt;JioAsp Maven Webapp&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;springframework.version&gt;4.0.3.RELEASE&lt;/springframework.version&gt;
          &lt;jackson.library&gt;2.7.5&lt;/jackson.library&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${springframework.version}&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;${springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${springframework.version}&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;${springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;${jackson.library}&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;1.5.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.4.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-commons&lt;/artifactId&gt;
      &lt;version&gt;1.12.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-commons-core&lt;/artifactId&gt;
      &lt;version&gt;1.4.1.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&lt;/version&gt;
   &lt;/dependency&gt;
  
          &lt;!-- dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-dataformat-xml&lt;/artifactId&gt;
              &lt;version&gt;${jackson.library}&lt;/version&gt;
          &lt;/dependency--&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;3.2&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;source&gt;1.7&lt;/source&gt;
                          &lt;target&gt;1.7&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-war-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.4&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;warSourceDirectory&gt;src/main/webapp&lt;/warSourceDirectory&gt;
                          &lt;warName&gt;JioAsp&lt;/warName&gt;
                          &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                          &lt;outputDirectory&gt;D:\apache-tomcat-8.0.33\webapps\&lt;/outputDirectory&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
          &lt;finalName&gt;JioAsp&lt;/finalName&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>spring-servlet.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:mongo="http://www.springframework.org/schema/data/mongo"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-4.0.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  http://www.springframework.org/schema/data/mongo
  "&gt;
  &lt;!-- http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
   --&gt;&lt;context:component-scan base-package="com.websystique.springmvc.controller" /&gt;
  &lt;context:component-scan base-package="com.websystique.springmvc.service" /&gt;
       &lt;!-- Configuration defining views files --&gt;
  
  
   &lt;!-- &lt;mongo:mongo host="localhost" port="27017" id="mongo" /&gt;
      &lt;mongo:db-factory dbname="aadhaar" mongo-ref="mongo" id="mongoDbFactory" /&gt;
  
       &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /&gt;
      &lt;/bean&gt; 
   --&gt;
      &lt;!-- &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;constructor-arg name="mongo" ref="mongo" /&gt;
          &lt;constructor-arg name="databaseName" value="ganesh" /&gt;
      &lt;/bean&gt; --&gt;
  
      &lt;!-- &lt;bean id="personDAO" class="com.springjdbc.mongojdbctemplateclass.MongoDBJDBCTemplate"&gt;
          &lt;constructor-arg name="mongoOps" ref="mongoTemplate"/&gt;
      &lt;/bean&gt; --&gt;
  
  &lt;!-- Factory bean that creates the Mongo instance --&gt;
   &lt;bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean"&gt;
      &lt;property name="host" value="localhost" /&gt;
  &lt;/bean&gt;
  &lt;!-- MongoTemplate for connecting and querying the documents in the database --&gt;
  &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
       &lt;constructor-arg name="mongo" ref="mongo" /&gt;
       &lt;constructor-arg name="databaseName" value="aadhaar" /&gt;
  &lt;/bean&gt; 
  &lt;/beans&gt;
  </code></pre>