服务器启动时报Error creating bean with name 'sqlMapClient' defined in class .

本文分析了一个关于Spring与Ibatis结合使用时出现的ClassNotFoundException异常案例。通过详细的错误日志和逐步排查,最终定位到问题是由新增SQL配置中的parameterClass属性引用了未正确配置的JavaBean引起的。
部署运行你感兴趣的模型镜像
服务器一启动就报如下的错误,当时依照错误提示很是不解:

1.Caused by: org.springframework.beans.factory.BeanCreationException:
2.Could not autowire field: private com.huawei.support.dao.DaoManager com.huawei.support.attachment.dao.AttachmentDAO.mDaoManager;
3.nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoManager':
4.Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.
5.BeanCreationException: Could not autowire method:
6.public void com.huawei.support.dao.DaoManager.setSqlMap(com.ibatis.sqlmap.client.SqlMapClient);
7.nested exception is org.springframework.beans.factory.
8.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in class
9.path resource [applicationContext.xml]: Invocation of init method failed; nested exception is
10.org.springframework.core.NestedIOException: Failed to parse config resource: class path resource
11.[sql-map-config.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML.
12.Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
13.Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
14.Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/select'.
15.Cause: com.ibatis.sqlmap.client.SqlMapException: Error. Could not initialize class. Cause: java.lang.ClassNotFoundException: com.szelink.zfaq.alarm.aqyj.action.AlarmWycgBean at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
16. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
17. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
18. ... 37 more



(1) 如上的错误提示,没有发现该类。但是在项目中确实存在所提到的类的。如是就想是不是我创建的applicationContext.xml配置文件中有问题。在该配置文件中创建bean有问题。
(2) 后来进一步的查找如下的错误提示引起了注意:

1.Cause: com.ibatis.sqlmap.client.SqlMapException: Error.
2.Could not initialize class.
3.Cause: java.lang.ClassNotFoundException:com.szelink.zfaq.alarm.aqyj.action.AlarmWycgBean

此时怀疑是不是在Ibatis的配置文件中新加的SQL引进了错误。如是删掉了刚刚添加的SQL发现,服务器启动正常。如是定位出使新加的SQL引进的问题的。新加的SQL如下所示:

<!-- 最新预警信息 -->
<select id="newWarnings" resultClass="java.util.HashMap" parameterClass="com.szelink.zfaq.alarm.aqyj.action.AlarmWycgBean">
<include refid="ORACLE_PAGE_HEADER" />
SELECT T.* ,G.ORG_NAME FROM (
SELECT UNITID,ALARMDATE,
SUM(CASE WHEN CATEGORY = '1' THEN NUMS ELSE 0 END) ONE,
SUM(CASE WHEN CATEGORY = '2' THEN NUMS ELSE 0 END) TWO,
SUM(CASE WHEN CATEGORY = '3' THEN NUMS ELSE 0 END) THREE,
SUM(CASE WHEN CATEGORY = '4' THEN NUMS ELSE 0 END) FOUR,
SUM(CASE WHEN CATEGORY = '5' THEN NUMS ELSE 0 END) FIVE,
SUM(CASE WHEN CATEGORY = '6' THEN NUMS ELSE 0 END) SIX,
SUM(CASE WHEN CATEGORY = '7' THEN NUMS ELSE 0 END) SEVEN,
SUM(CASE WHEN CATEGORY = '99' THEN NUMS ELSE 0 END) OTHER,
SUM(NUMS) TOTAL
FROM(
SELECT R.UNITID , D.CATEGORY , R.ALARMDATE,SUM(D.NUMS) NUMS FROM T_ALARM_REVIEWS R
INNER JOIN T_ALARM_REVIEWS_DETAILS D ON R.TID = D.PTID
GROUP BY R.UNITID , D.CATEGORY , R.ALARMDATE
) GROUP BY UNITID ,ALARMDATE
) T INNER JOIN Z_RES_ORG G ON T.UNITID = G.ORG_ID ORDER BY ALARMDATE DESC, TOTAL DESC
<include refid="ORACLE_PAGE_FOOTER" />
</select>

(3)最后经过分析发现 parameterClass="com.szelink.zfaq.alarm.aqyj.action.AlarmWycgBean" 在配置文件中并没有这样的一个别名,它是对应到一个类的。由于没有配置导致Server在解析配置文件时无法识别该类,而导致Cause: java.lang.ClassNotFoundException: com.szelink.zfaq.alarm.aqyj.action.AlarmWycgBean
(4)最终可以这样解决:在parameterClass中写入自己类对应的javabean

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'borrowApplicationController' defined in URL [jar:file:/opt/ar chive/app/archives-admin.jar!/BOOT-INF/classes!/com/archives/web/controller/borrow/BorrowApplicationController.class]: Unsatisfied dependency expressed throug h constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'borrowApplicat ionService': Unsatisfied dependency expressed through field 'wfCommonService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyExce ption: Error creating bean with name 'wfCommonService': Unsatisfied dependency expressed through field 'wfInstanceService'; nested exception is org.springfram ework.beans.factory.BeanCreationException: Error creating bean with name 'wfInstanceServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositoryServiceBean' defined in class path resource [org /flowable/spring/boot/ProcessEngineServicesAutoConfiguration.class]: Unsatisfied dependency expressed through method 'repositoryServiceBean' parameter 0; nest ed exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout);
11-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值