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。
报错解决!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值