title: Spring MVC, Hibernate project throws IncompatibleClassChangeError (Tomcat 7)
body: <p>I am new to Spring source and Spring Maven (Spring MVC) project. I am trying to connect project with Database using Hibernate 4.1.8. But there is an error while running the project in Tomcat 7.0 server for localhost.</p>
  
  <p>The error is as follows:</p>
  
  <pre><code>type Exception report
  
  message Servlet.init() for servlet appServlet threw exception
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception 
  
  javax.servlet.ServletException: Servlet.init() for servlet appServlet threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  
  
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      javax.servlet.GenericServlet.init(GenericServlet.java:160)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  
  
  root cause
  
  java.lang.IncompatibleClassChangeError: Implementing class
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClass(Unknown Source)
      java.security.SecureClassLoader.defineClass(Unknown Source)
      org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
      org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      java.lang.Class.getDeclaredConstructors0(Native Method)
      java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
      java.lang.Class.getConstructor0(Unknown Source)
      java.lang.Class.getDeclaredConstructor(Unknown Source)
      org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
      org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:818)
      org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:549)
      org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      javax.servlet.GenericServlet.init(GenericServlet.java:160)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>The <strong>servlet-context.xml</strong> file is as follows. It contains the beans that I have added for connecting with Hibernate:</p>
  
  <pre><code>&lt;!-- JDBC settings --&gt;    
      &lt;beans:bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;beans:property name="location" value="resources/config.properties" /&gt;        
      &lt;/beans:bean&gt;
  
  &lt;beans:bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;beans:property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
          &lt;beans:property name="url" value="${jdbc.url}" /&gt;
          &lt;beans:property name="username" value="${jdbc.username}" /&gt;
          &lt;beans:property name="password" value="${jdbc.password}" /&gt;
      &lt;/beans:bean&gt;
  
  &lt;!-- Model classes that maps to database fields --&gt;
      &lt;beans:bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
  
          &lt;beans:property name="dataSource" ref="dataSource" /&gt;
          &lt;beans:property name="annotatedClasses"&gt;
              &lt;beans:list&gt;
                  &lt;beans:value&gt;com.doxonomy.model.User&lt;/beans:value&gt;              
              &lt;/beans:list&gt;
          &lt;/beans:property&gt;
          &lt;beans:property name="configLocation"&gt;          
              &lt;beans:value&gt;classpath:hibernate.cfg.xml&lt;/beans:value&gt;
          &lt;/beans:property&gt;               
          &lt;!-- Hibernate configuration --&gt;
          &lt;beans:property name="hibernateProperties"&gt;
              &lt;beans:props&gt;
                  &lt;beans:prop key="hibernate.dialect"&gt;
                      org.hibernate.dialect.MySQLDialect
                  &lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.show_sql"&gt;false&lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.transaction.flush_before_completion"&gt;true&lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.hbm2ddl.auto"&gt;
                      create
                  &lt;/beans:prop&gt;
              &lt;/beans:props&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="userDAOImpl" class="com.doxonomy.dao.UserDAOImpl" /&gt;
  </code></pre>
  
  <p>The pom.xml dependency is as follows:</p>
  
  <pre><code>&lt;dependencies&gt;
          &lt;!-- Spring --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework-version}&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;!-- Exclude Commons Logging in favor of SLF4j --&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                      &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                   &lt;/exclusion&gt;
              &lt;/exclusions&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;${org.springframework-version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- AspectJ --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
              &lt;version&gt;${org.aspectj-version}&lt;/version&gt;   
          &lt;/dependency&gt;   
  
          &lt;!-- Logging --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;${org.slf4j-version}&lt;/version&gt; 
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
              &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;          
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
              &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;          
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.15&lt;/version&gt;           
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;javax.mail&lt;/groupId&gt;
                      &lt;artifactId&gt;mail&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;javax.jms&lt;/groupId&gt;
                      &lt;artifactId&gt;jms&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;com.sun.jdmk&lt;/groupId&gt;
                      &lt;artifactId&gt;jmxtools&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;com.sun.jmx&lt;/groupId&gt;
                      &lt;artifactId&gt;jmxri&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- @Inject --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.inject&lt;/groupId&gt;
              &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;
              &lt;version&gt;1&lt;/version&gt;    
          &lt;/dependency&gt;
  
          &lt;!-- Servlet --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
              &lt;version&gt;2.5&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt; 
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
              &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;commons-pool&lt;/groupId&gt;
              &lt;artifactId&gt;commons-pool&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Javax Persistance --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;persistence-api&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;          
          &lt;/dependency&gt;
  
          &lt;!-- Hibernate --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;4.1.8.Final&lt;/version&gt;                      
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
              &lt;version&gt;3.0alpha&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- MySQL database driver --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.9&lt;/version&gt;
          &lt;/dependency&gt;       
  
         &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              version&gt;1.2.2&lt;/version&gt;                     
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-dao&lt;/artifactId&gt;
              &lt;version&gt;2.0.3&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
              &lt;version&gt;2.0.6&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
              &lt;version&gt;3.1.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;        
  
          &lt;!-- Test --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;  
              &lt;version&gt;4.8.1&lt;/version&gt;            
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;        
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>I have created a base class for getting values from Database. It is <strong>UserDAOImpl</strong>, which has been developed using various example and looks fine. What needs to be done to resolve this error?</p>