java.lang.NoClassDefFoundError: org/hibernate/annotations/Entity

以前遇到異常都寫在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。
報錯解決!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章