升级到Spring 3.2.4后获取错误NoClassDefFoundError

时间:2013-10-25 17:59:57

标签: java spring hibernate spring-mvc hibernate-mapping

我在Spring 2.5上使用Hibernate3.jar,现在我已经升级到Spring 3.2.4并仍在使用Hibernate3.jar 但是在应用程序负载上我得到的误差低于误差,如果我遗漏任何东西,请帮助我。

2013-10-25 23:20:19,513 ERROR [org.springframework.web.servlet.DispatcherServlet] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/eam/deploy/tfcc-admin.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

我在lib文件夹中添加了以下jar文件,

spring-aop-3.2.4.RELEASE.jar
spring-aspects-3.2.4.RELEASE.jar
spring-beans-3.2.4.RELEASE.jar
spring-context-3.2.4.RELEASE.jar
spring-context-support-3.2.4.RELEASE.jar
spring-core-3.2.4.RELEASE.jar
spring-expression-3.2.4.RELEASE.jar
spring-jdbc-3.2.4.RELEASE.jar
spring-orm-3.2.4.RELEASE.jar
spring-tx-3.2.4.RELEASE.jar
spring-web-3.2.4.RELEASE.jar
spring-webmvc-3.2.4.RELEASE.jar

SessionFactoryBean配置:

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="mappingResources">
            <list>
                <value>com/eam/hibernate/User.hbm.xml</value>
                <value>com/eam/hibernate/Branch.hbm.xml</value>
                <value>com/eam/hibernate/Address.hbm.xml</value>
            </list>
        </property>
    </bean>

感谢。

3 个答案:

答案 0 :(得分:1)

我通过做以下事情解决了这个问题, 1.删​​除旧的hibernate3.jar和hibernate-annotation.jar并添加两个新的jar

hibernate-commons-annotations-3.2.0.Final.jar
hibernate-core-3.6.10.Final.jar
persistence-api-1.0.jar

现在我在类路径中跟随弹簧相关的jar。

spring-aop-3.2.4.RELEASE.jar
spring-aspects-3.2.4.RELEASE.jar
spring-beans-3.2.4.RELEASE.jar
spring-context-3.2.4.RELEASE.jar
spring-context-support-3.2.4.RELEASE.jar
spring-core-3.2.4.RELEASE.jar
spring-expression-3.2.4.RELEASE.jar
spring-jdbc-3.2.4.RELEASE.jar
spring-orm-3.2.4.RELEASE.jar
spring-tx-3.2.4.RELEASE.jar
spring-web-3.2.4.RELEASE.jar
spring-webmvc-3.2.4.RELEASE.jar

谢谢,

答案 1 :(得分:0)

抱歉,我现在找不到信息,但我对此有记忆。 尝试将其替换为:

class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

答案 2 :(得分:0)

  • 验证您的类路径中是否还有hibernate3.jar
  • 确保您已删除旧spring 2.5 jar的依赖项。 (但即使存在冲突,也可能是NoClassDef,弹簧类不是hibernate
  • 检查是否删除了hibernate3.jar所依赖的任何jar。这可能不允许org/hibernate/context/CurrentSessionContext初始化。 (堆栈跟踪中可能有ExceptionInInitializerError

我在这里列出了可能由NoClassDefFoundError引起的问题,可以帮到你:

Debugging a NoClassDefFoundError