今天从云开发平台上生成的代码报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方法测试。

结果测试可行!

最新文章

  1. struts2笔记(2)
  2. 将对象转化成json字符串
  3. PARSEC-3.0编译错误
  4. ECSHOP农行支付接口开发(含手机端)
  5. Node学习
  6. B2B电子商务网站技术框架
  7. OpenGL学习进程(11)第八课:颜色绘制的详解
  8. 51nod 1092 回文字符串 (dp)
  9. 不一样的风格,C#的lambda表达式
  10. easyui combobox赋值
  11. TF卡速度测试对比 Class数越高速度越快
  12. POJ 2251 Dungeon Master(地牢大师)
  13. MySQL完全备份、增量备份与恢复[转]
  14. CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法
  15. Linux内核内存管理算法Buddy和Slab: /proc/meminfo、/proc/buddyinfo、/proc/slabinfo
  16. future then
  17. [原创]K8 Cscan 3.6大型内网渗透自定义扫描器
  18. ORACLE SQL Developer日期显示格式不全
  19. Linux遇到的问题(一)Ubuntu报“xxx is not in the sudoers file.This incident will be reported” 错误解决方法
  20. linux下编译upx 3.93

热门文章

  1. 【C/C++】获取当前系统时间
  2. Java笔记(四)
  3. NLP | 自然语言处理 - 语言模型(Language Modeling)
  4. PHP + zTree插件树型文件夹显示
  5. Flutter从入门到进阶实战携程网App_汇总贴
  6. Flutter实战视频-移动电商-21.分类页_类别信息接口调试
  7. maven:mirrors和repository的关系区别
  8. java 关于getProperty()方法中反斜杠问题
  9. jQuery 学习笔记(一)jQuery 语法
  10. HDU - 1099 - Lottery - 概率dp