启动tomcat报错org.hibernate.cache.CacheProvider

简介:

项目是使用spring ,hibernateJava Web项目,启动时报错:

Xml代码   收藏代码
  1. Caused by: java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;  
  2.     at java.lang.Class.getDeclaredFields0(Native Method)  
  3.     at java.lang.Class.privateGetDeclaredFields(Class.java:2291)  
  4.     at java.lang.Class.getDeclaredFields(Class.java:1743)  
  5.     at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:374)  
  6.     at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:322)  
  7.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:840)  
  8.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:495)  
  9.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)  
  10.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)  
  11.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)  
  12.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)  
  13.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)  
  14.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:270)  
  15.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)  
  16.     at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)  
  17.     at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)  
  18.     at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550)  
  19.     at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:159)  
  20.     at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)  
  21.     at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)  
  22.     ... 31 more  

 spring 的配置文件(beans.xml)如下:

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  6.            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
  7.             http://www.springframework.org/schema/context  
  8.            http://www.springframework.org/schema/context/spring-context-3.1.xsd  
  9.            http://www.springframework.org/schema/aop  
  10.            http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
  11.            http://www.springframework.org/schema/tx   
  12.            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" default-lazy-init="true" >  
  13.              
  14.     <context:annotation-config />  
  15.     <context:component-scan base-package="com" />  
  16.        
  17.        
  18.     <bean id="dataSource" destroy-method="close"  
  19.         class="org.apache.commons.dbcp.BasicDataSource">  
  20.         <property name="driverClassName" value="${jdbc.driverClassName}" />  
  21.         <property name="url" value="${jdbc.url}" />  
  22.         <property name="username" value="${jdbc.username}" />  
  23.         <property name="password" value="${jdbc.password}" />  
  24.     </bean>  
  25.     <bean  
  26.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  27.         <property name="locations">  
  28.             <value>classpath:jdbc.properties</value>  
  29.         </property>  
  30.     </bean>  
  31.   
  32.   
  33.     <bean id="sessionFactory"  
  34.         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
  35.         <property name="dataSource" ref="dataSource" />  
  36.         <property name="packagesToScan">  
  37.             <list>  
  38.                 <value>com.kingbase.domain</value>  
  39.   
  40.             </list>  
  41.         </property>  
  42.         <property name="hibernateProperties">  
  43.             <props>  
  44.             <prop key="hibernate.dialect">  
  45.                     org.hibernate.dialect.MySQLDialect  
  46.                 </prop>  
  47.                 <!-- <prop key="hibernate.dialect">  
  48.                     org.hibernate.dialect.PostgreSQLDialect  
  49.                 </prop> -->  
  50.                 <prop key="hibernate.show_sql">true</prop>  
  51.                 <prop key="hibernate.format_sql">true</prop>  
  52.                 <prop key="hibernate.hbm2ddl.auto">update</prop>  
  53.                 <prop key="current_session_context_class">thread</prop>  
  54.             </props>  
  55.         </property>  
  56.     </bean>  
  57.   
  58.   
  59.     <bean id="txManager"  
  60.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  61.         <property name="sessionFactory" ref="sessionFactory"></property>  
  62.     </bean>  
  63.     <!-- 事务的注解,如 @Transactional(readOnly=true)   -->  
  64.     <!--<tx:annotation-driven transaction-manager="txManager" /> 
  65.  
  66.     -->  
  67.     <aop:config>  
  68.         <aop:pointcut id="bussinessService"  
  69.             expression="execution(public * com.kingbase.dao..*.*(..))" />  
  70.         <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />  
  71.     </aop:config>  
  72.   
  73.     <tx:advice id="txAdvice" transaction-manager="txManager">  
  74.         <tx:attributes>  
  75.             <tx:method name="check*" read-only="true" />  
  76.             <tx:method name="count*" read-only="true" />  
  77.             <tx:method name="search*" read-only="true" />  
  78.             <tx:method name="get*" read-only="true" />  
  79.             <tx:method name="test*" read-only="true" />  
  80.             <tx:method name="is*" read-only="true" />  
  81.             <tx:method name="show*" read-only="true" />  
  82.             <tx:method name="delete*" propagation="REQUIRED" />  
  83.             <tx:method name="update*" propagation="REQUIRED" />  
  84.             <tx:method name="save*" propagation="REQUIRED" />  
  85.             <tx:method name="add*" propagation="REQUIRED" />  
  86.             <tx:method name="set*" propagation="REQUIRED" />  
  87.             <tx:method name="verify*" propagation="REQUIRED" />  
  88.             <tx:method name="create*" propagation="REQUIRED" />  
  89.             <tx:method name="judge*" propagation="REQUIRED" />  
  90.         </tx:attributes>  
  91.     </tx:advice>  
  92.   
  93.   
  94.   
  95.   
  96.       
  97. </beans>  

我使用hibernate的版本是:4.2.2.Final 

spring的版本是:3.2.3.RELEASE

 

原因:hibernate的版本升为4了,但是配置文件中仍使用的是hibernate3

 

解决办法:

把spring配置文件中的

org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean

改为:

org.springframework.orm.hibernate4.LocalSessionFactoryBean

就OK 了

详情请参阅:http://stackoverflow.com/questions/7528862/exception-noclassdeffounderror-for-cacheprovider

相关文章
|
7月前
|
Java 应用服务中间件 Apache
Tomcat 发布jsp报错
Tomcat 发布jsp报错
|
1月前
|
Java 应用服务中间件 Shell
Tomcat 安装配置教程及成功后,启动失败报错解决方案
Tomcat 安装配置教程及成功后,启动失败报错解决方案
41 0
|
1月前
|
前端开发 Java 应用服务中间件
springboot 升级(1.5.7.RELEASE升级到2.7.10) Tomcat启动报错
springboot 升级(1.5.7.RELEASE升级到2.7.10) Tomcat启动报错
|
7月前
|
应用服务中间件
Tomcat报错:The required Server component failed to start so Tomcat is unable to start
Tomcat报错:The required Server component failed to start so Tomcat is unable to start
115 0
|
7月前
|
Java 应用服务中间件 容器
Tomcat报错 严重: A child container failed during start
Tomcat报错 严重: A child container failed during start
|
1月前
|
Java 应用服务中间件
解决tomcat启动报错:无法在web.xml或使用此应用程序部署的jar文件中解析绝对的url [http:java.sun.com/jsp/jstl/core]
解决tomcat启动报错:无法在web.xml或使用此应用程序部署的jar文件中解析绝对的url [http:java.sun.com/jsp/jstl/core]
756 1
|
1月前
|
Java 应用服务中间件
Tomcat 报错:The origin server did not find a current representation for the target resource
Tomcat 报错:The origin server did not find a current representation for the target resource
44 1
|
1月前
|
监控 应用服务中间件
idea debug模式启动Tomcat报错:Error running ‘tomcat8‘: java.net.SocketException “socket closed“
idea debug模式启动Tomcat报错:Error running ‘tomcat8‘: java.net.SocketException “socket closed“
|
6月前
|
Java 应用服务中间件
解决java.lang.NoClassDefFoundError: JspException异常——Tomcat常见报错总结
解决java.lang.NoClassDefFoundError: JspException异常——Tomcat常见报错总结
61 0
|
7月前
|
应用服务中间件
IDEA启动报错:Error running ‘Tomcat 8.5.34‘: Address localhost:1099 is already in use
IDEA启动报错:Error running ‘Tomcat 8.5.34‘: Address localhost:1099 is already in use
58 0