4

我正在从事Java web开发,使用spring3.1.1+hibernate3.6.0+tomcat7.0.29 + mysql5.5,但是在我的服务器上运行后,Eclipse提示

 HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError:       org/springframework/orm/hibernate3/support/HibernateDaoSupport 

并详细如下,输入异常报告

message Handler processing failed; nested exception is java.lang.NoClassDefFoundError:            org/springframework/orm/hibernate3/support/HibernateDaoSupport

description The server encountered an internal error (Handler processing failed; nested exception is java.lang.NoClassDefFoundError:     org/springframework/orm/hibernate3/support/HibernateDaoSupport) that prevented it from fulfilling this request. 

例外

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError:       org/springframework/orm/hibernate3/support/HibernateDaoSupport



org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)


org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
root cause 

java.lang.NoClassDefFoundError:   org/springframework/orm/hibernate3/support/HibernateDaoSupport 
java.lang.ClassLoader.defineClass1(Native Method) 
java.lang.ClassLoader.defineClass(ClassLoader.java:791) 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
 org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2901)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) 
cc.fanbang.api.manager.DBManager.addUser(DBManager.java:139) 
 cc.fanbang.api.controller.TestController.handleDBManagerTestRequest(TestController.java:42)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
java.lang.reflect.Method.invoke(Method.java:601) 
 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
  org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
root cause 

java.lang.ClassNotFoundException:      org.springframework.orm.hibernate3.support.HibernateDaoSupport 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) 
java.lang.ClassLoader.defineClass1(Native Method) 
java.lang.ClassLoader.defineClass(ClassLoader.java:791) 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2901)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) 
cc.fanbang.api.manager.DBManager.addUser(DBManager.java:139) 
     cc.fanbang.api.controller.TestController.handleDBManagerTestRequest(TestController.java:42)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
java.lang.reflect.Method.invoke(Method.java:601) 
   org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
   org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
  org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 

我不明白为什么它告诉我没有hibernatedaosupport,我已经将它导入到项目中引用的库和web-inf/lib中。我导入的包如下,

 commons-beanutils-1.8.3.jar 
    commons-coder-1.4.jar 
    commons-io-2.3.jar 
    commons-lang-2.6.jar 
    commons-logging-1.1.1.jar 
    ezorph-1.0.6.jar 
    json-lib-2.4-jdk15.jar 
    jstl-1.2.jar 
    org.springframework.asm-3.1.1.release.jar 
    org.springframework.beans-3.1.1.release.jar 
    org.springframework.context-3.1.1.release.jar 
    org.springframework.core-3.1.1.release.jar 
    org.springframework.expression-3.1.1.release.jar 
    org.springframework.web.servlet-3.1.1.release.jar 
    org.springframework.web-3.1.1.release.jar 
    servlet-api.jar 
    antlr-2.7.6 
    c3p0-0.9.1.jar 
    commons-collections-3.1.jar 
    dom4j-1.6.1.jar 
    ehcache-1.5.0.jar 
    hibernate-jpa-2.0-api-1.0.1.final.jar 
    hibernate3.jar 
    javassist-3.12.0.ga.jar 
    jta-1.1.jar 
    mysql-connector-java-5.1.12-bin.jar 
    org.springframework.orm-3.1.1.release.jar 
    org.springframework.jdbc-3.1.1.release.jar 
    org.springframework.aop-3.1.1.release.jar 
    org.springframework.transaction-3.1.1.release.jar 
    slf4j-api-1.6.1.jar 
    slf4j-nop-1.6.1.jar 

applicationContext.xml中与事务处理相关的部分内容如下,

<bean id="transactionManager"           class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" />  
</bean> 

<tx:advice id="txAdvice" transaction-manager="transactionManager"> 
    <tx:attributes> 
        <tx:method name="get*" read-only="true" /> 
        <tx:method name="*" /> 
    </tx:attributes> 
</tx:advice> 

<aop:config> 
    <aop:pointcut id="fbPointcut" expression="bean(dbManager)" /> 
    <aop:advisor advice-ref="txAdvice" pointcut-ref="fbPointcut" /> 
</aop:config>
4

3 回答 3

3

NoClassDefFoundError意味着类加载器找不到org.springframework.orm.hibernate3.support.HibernateDaoSupport依赖的类。并不是说它HibernateDaoSupport本身就不见了。查找缺少哪个依赖项的最佳方法是查看HibernateDaoSupport

您的类路径中似乎缺少org.springframework.dao库。

于 2012-09-23T16:15:41.137 回答
1

我认为这是因为你spring-orm的库中有一个不同版本的 jar,它有这个org.springframework.orm.hibernate3.support.HibernateDaoSupport类。

spring-orm 3.1 jar添加到您的库中。您可以在底部找到 jar 下载链接。

一般来说,如果你得到一个NoClassDefFoundError, google 为有类的 jar。Maven 中央存储库是这样做的好地方。

您的 spring aop、jdbc 和事务 jar 也有不同的版本(3.0.7 而不是 3.1.1)。始终使用相同版本的罐子。如果您使用不同版本的 jar,应用程序可能会抛出一些错误。

于 2012-09-24T02:35:39.593 回答
0

14.3 Hibernate

We will start with a coverage of Hibernate 3 in a Spring environment, using it to demonstrate the approach that Spring takes towards integrating O/R mappers. This section will cover many issues in detail and show different variations of DAO implementations and transaction demarcation. Most of these patterns can be directly translated to all other supported ORM tools. The following sections in this chapter will then cover the other ORM technologies, showing briefer examples there.

Note: As of Spring 3.0, Spring requires Hibernate 3.2 or later.

Source: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/orm.html#orm-hibernate

Your Hibernate Version is too old.

On re-reading your question, you say you are using Hibernate 3.6, yet you list hibernate3.jar among your dependencies. Which is it?

于 2012-09-24T14:34:03.783 回答