Spring3+Hibernate4整合时出错 Failed to read candidate component class:

在尝试将Spring3.2.3RELEASE与Hibernate4.2.21Final进行整合时,遇到了'Failed to read candidate component class'的错误。起初误认为是Java 1.8版本不兼容Spring 3,于是降级到1.7,但问题未解决。实际上,错误的根本原因是配置文件中的扫描路径错误,原本设置为了'entity'。修正扫描路径后,成功完成Spring和Hibernate的整合。

错误信息:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [F:\Program Files\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\testsh\WEB-INF\classes\entity\Department.class]; 
nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [F:\Program Files\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\testsh\WEB-INF\classes\entity\Department.class]; 
nested exception is java.lang.IllegalArgumentException

版本信息:

spring3.2.3RELEASE    hibernate4.2.21Final   jdk1.8


一直报上边的错误

百度说java1.8版本只支持spring4.0以上,所以我就把web项目的jdk调为1.7版本,这个错误解决了,但是出现了一个新问题。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainController': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private service.EmpService controller.MainController.empService; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.EmpService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

原因是我配置文件中扫描路径写错了,写成entity

<context:component-scan base-package="*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

修改之后就可以正常访问了,整合成功~~~



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值