1

我在 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>

谢谢。

4

3 回答 3

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

现在我在我的类路径中有以下与弹簧相关的罐子。

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

谢谢,

于 2013-10-26T03:28:03.537 回答
0
  • 验证您的类路径中是否还有 hibernate3.jar
  • 确保您已删除旧 spring 2.5 jar 的依赖项。(但即使发生冲突,它也会是 NoClassDef 与 spring 类不休眠
  • 检查是否删除了 hibernate3.jar 所依赖的任何 jar。这可能不允许org/hibernate/context/CurrentSessionContext初始化。(可能有一个ExceptionInInitializerError堆栈跟踪)

我在这里列出了 NoClassDefFoundError 的可能原因,可能会对您有所帮助:

调试 NoClassDefFoundError

于 2013-10-25T19:48:42.940 回答
0

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

class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
于 2013-10-25T18:42:10.003 回答