码迷,mamicode.com
首页 > 编程语言 > 详细

hibernate4 , spring3 使用 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean 报错 Implementing class

时间:2015-01-06 19:51:18      阅读:503      评论:0      收藏:0      [点我收藏+]

标签:

错误代码如下

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory‘ defined in URL [file:/D:/eclipse3/workspace/diancai_parent/diancai_web/src/main/webapp/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
	... 79 more
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
	at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)
	at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
	at java.lang.Class.getConstructor0(Class.java:2699)
	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:818)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:549)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
	... 86 more

  我使用的是 spring 3 + hibernate-core-4.1.8.Final + hibernate.3.2.ga  

我想使用注解方式 把对象 映射到 数据库 ,刚开始用的 是 hbm.xml 为每个对象配置映射方式,太麻烦 。 就想换成 注解方式。 很遗憾报上面的错误,

查了好多,都是说 jar包重复,但是发现没有。

最后解决: 去掉 hibernate.3.2.ga  ,把 hibernate-core4  换成 hibernate-core-3.5.0-Final ,就不报错了 。。如何是maven 管理项目,记得多清理几次项目

  

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <!-- org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean -->
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
        <!-- <property name="packagesToScan" value="com.diancai.shiro.entity"></property> -->
        <!-- <property name="mappingLocations">
            <list>
                <value>classpath:hibernateOrm/*.hbm.xml</value>                
            </list>
        </property> -->
        <property name="annotatedClasses" value="com.diancai.shiro.entity.User"></property>
    </bean>

 

hibernate4 , spring3 使用 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean 报错 Implementing class

标签:

原文地址:http://www.cnblogs.com/zhangchenglzhao/p/4206601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!