以前遇到异常都写在txt上,以后都陆续发在网上吧,便于以后回忆也可以和遇到同样问题的小伙伴探讨下。
今天SSH整合hibernate,struts时候遇到下面报错!
17-03-19 18:41:42,063
ERROR (org.springframework.web.context.ContextLoader:308) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]:
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity
......
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity
......
Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity
......
Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.Entity
......
首先根据上面信息可以知道sessionFactory(会话工厂)这个bean实例化失败。
再往下看它说org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean这个类实例化失败,因为构造函数抛出异常。
最后它说没有找到这个java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity这个类。
查看源码:
发现确实是new 了一个Entity类,而我没有导org.hibernate.annotations.jar这个包。但是只导这一个包还是会报错。
索性我导了使用注解Annotation时用的jar包。 包括: hibernate-commons-annotations-3.3.0.ga.jar hibernate-entitymanager.jar ejb3-persistence.jar hibernate-annotations.jar。
报错解决!!!