Spring相关BUG
今天从云开发平台上生成的代码报Spring相关的错误。
我找到第一处错误,整理如下:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'kmBookDetailTarget' defined in ServletContext resource [/WEB-INF/KmssConfig/km/book/spring.xml]: Error setting property values;
nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'kmBookCategoryService' of bean class [com.landray.kmss.km.book.service.spring.KmBookDetailServiceImp]: Bean property 'kmBookCategoryService' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
首先翻译一遍:
创建定义在这个spring.xml文件里面,名为'kmBookDetailTarget'的bean时出错:设置属性值时出错;
嵌套异常为这个Exception:这个bean类的属性'kmBookCategoryService'无效:bean属性'kmBookCategoryService'是不可写或者有一个无效的setter方法。
setter的参数类型是否与getter的返回类型匹配?
然后确定了导致错误的起源在这个spring.xml文件,并且找到'kmBookDetailTarget'这个bean,然后找到这个bean里面的属性'kmBookCategoryService',如图:

bean每注入一个属性,我们都要在这个bean对应的class中定义setter方法,我们找到这个class,如图:

发现没有任何setter方法。其实baseDao这个属性应该是在框架中已经setter过了,即父类中定义了,而我们自定义的属性'kmBookCategoryService'并没有定义,因此才导致错误。
解决办法:
删掉该属性,如图:

clean项目,重新启动,OK!
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
那么如果我不删除spring配置,该如何做?
应该在对应的类里面添加setter方法,如图:

重新启动,欸~都挺好,也OK!
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
但如果,我就是要删除这个spring配置,但是以后我还是想要用这个属性怎么办?
我们可以通过另外一种办法使用:

SpringBeanUtil是我们封装的类,针对这个方法的代码如下:
private static ApplicationContext applicationContext = null;
public static Object getBean(String beanName) {
if (applicationContext == null)
return null;
return applicationContext.getBean(beanName);
}
好不好用测试才行,很不幸,我们框架没有单元测试(我自己也不会搞),于是我从前端写了一个ajax,然后到action层调service,最后在serviceImp调test方法测试。
结果测试可行!
Spring相关BUG的更多相关文章
- SQL Server 优化器特性导致的内存授予相关BUG
我们有时会遇到一些坑,要不填平,要不绕过.这里为大家介绍一个相关SQL Server优化器方面的特性导致内存授予的相关BUG,及相关解决方式,也顺便回答下邹建同学的相关疑问. 问题描述 一个简单的查询 ...
- maven引入spring相关依赖
<!--spring相关包--> <dependency> <groupId>org.springframework</groupId> <art ...
- spring相关注解
spring相关注解: 使用之前需要<context:annotation-config/>在配置文件中启用 @Required 应用于类属性的set方法,并且要求该属性必须在xml容器里 ...
- Spring 相关目录
Spring 相关目录 学习笔记 Spring 学习笔记 IoC 基础 Spring 学习笔记 Resource 资源 Spring 学习笔记 数据绑定,校验,BeanWrapper 与属性编辑器 源 ...
- Spring相关jar说明
Spring整合使用说明 一.只是使用spring框架 dist\spring.jar lib\jakarta-commons\commons-logging.jar 如果使用到了切面编程(AOP), ...
- 搭建Spring相关框架后,配置信息文件头部出现红色小×错误。
问题描述: 在搭建关于Spring相关框架的时候,在applicationContext.xml配置文件和servlet-mvc.xml配件文件的头部会出现一个红色的小X错误: 错误描述: Refer ...
- Win10 LTSC 2021 安装及相关bug解决
Win10 LTSC 2021 安装及相关bug解决 目录 Win10 LTSC 2021 安装及相关bug解决 准备文件 系统安装 系统激活 修复CPU占用高和输入法显示bug 安装微软应用商店 推 ...
- 经过一个多月的等待我有幸成为Spring相关项目的Contributor
给开源项目尤其是Spring这种知名度高的项目贡献代码是比较难的,起码胖哥是这么认为的.有些时候我们的灵感未必契合作者的设计意图,即使你的代码十分优雅. 我曾经给Spring Security提交了一 ...
- spring相关jar包的含义
spring.jar是包含有完整发布的单个jar 包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下才会用到 spring-m ...
随机推荐
- 基于aspectj实现AOP操作的两种方式——注解方式
- Ubuntu 16.04 安装wine
1.安装源 sudo add-apt-repository ppa:wine/wine-builds sudo apt-get update 2.安装wine sud ...
- C++之remove和remove_if
一.Remove()函数 remove(beg,end,const T& value) //移除区间{beg,end)中每一个“与value相等”的元素: remove只是通过迭代器的指针向前 ...
- bzoj 4668 冷战——并查集结构
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4668 不路径压缩,维护并查集的树的结构,查询链上最大值.按秩合并就可以暴爬. #includ ...
- Spark Streaming之二:StreamingContext解析
1.1 创建StreamingContext对象 1.1.1通过SparkContext创建 源码如下: def this(sparkContext: SparkContext, batchDurat ...
- final/finalize/finally的区别
一.性质不同 (1)final为关键字: (2)finalize()为方法:---垃圾回收机制中的方法(GC) (3)finally为为区块标志,用于try语句中: 二.作用 (1)final为用于标 ...
- C# 计算时间日期
System.DateTime datetime = System.DateTime.Now.AddSeconds(fixtime); // fixtime 是往后的秒数 : datetime是现在时 ...
- mongodb "$"的作用
{ "_id": ObjectId("58e48e32830f398e8f401a95"), "_class": "com.ydd ...
- 技术胖Flutter第四季-22页面跳转并返回数据
视频地址: https://www.bilibili.com/video/av35800108/?p=23 博客地址: https://jspang.com/post/flutter4.html#to ...
- html5代码如何转成小程序代码
插件源码 链接:https://pan.baidu.com/s/1pGY8ZsdESaQGEzoEgpb_Rw 提取码:s1ix 放到与pages文件夹同级目录下 js中调用 //引入 var wx ...