1、错误提示:

Error setting property values:说找不到Printer中的设置属性值,然后去看一下,配置文件

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'printer' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'ink' of bean class [myprinter.Printer]: Bean property 'ink' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1685)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)at myspring.testHelloSpring.main(testHelloSpring.java:21)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'ink' of bean class [myprinter.Printer]: Bean property 'ink' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243)at org.springframework.beans.AbstractNestablePropertyAccessor.processLocalProperty(AbstractNestablePropertyAccessor.java:426)at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:278)at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:266)at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:97)at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:77)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1681)... 9 more

2、配置文件内容:

配置文件中显示,id="printer"下,有两个属性值,分别是:ink与paper。找不到这两个值,说明:Printer类中没有进行设置。然后,找到Printer类:

 <!-- Printer --><bean id="colorInk" class="myprinter.ColorInk"/><bean id="greyInk" class="myprinter.GreyInk"/><bean id="a4Paper" class="myprinter.TextPaper"><property name="charPerline" value="10"/><property name="linePerPage" value="8"/></bean><bean id="b5Paper" class="myprinter.TextPaper"><property name="charPerLine" value="6"/><property name="LinePerPage" value="5"/></bean><bean id="printer" class="myprinter.Printer"><property name="ink" ref="colorInk"/><property name="paper" ref="b5Paper"/></bean>

3、Printer类:

发现有两个变量,没有对其进行setter与getter,这两个方法恰巧是配置文件用来进行获取值得方法,也可以说进行了方法注入。

package myprinter;public class Printer {private Ink ink=null;private Paper paper=null;public void print(String str) {System.out.println("使用"+ink.getColor(255, 200, 0)+"颜色打印:\n");for(int i=0;i<str.length();++i) {paper.putInChar(str.charAt(i));}System.out.println(paper.getContent());}}

所以,补全方法实现:

package myprinter;public class Printer {private Ink ink=null;private Paper paper=null;public void print(String str) {System.out.println("使用"+ink.getColor(255, 200, 0)+"颜色打印:\n");for(int i=0;i<str.length();++i) {paper.putInChar(str.charAt(i));}System.out.println(paper.getContent());}public Ink getInk() {return ink;}public void setInk(Ink ink) {this.ink = ink;}public Paper getPaper() {return paper;}public void setPaper(Paper paper) {this.paper = paper;}}

最后,便可以进行实现了。

使用#ffc800颜色打印:jdkddn
mbfjkd
sbskjd
hsjkhf
djkhlk
==第1页==hflkhd
fkljhk
alncxj
skhsjf
dskjdh
==第2页==a.lkfh
jlkahn
jflkan
knfkfk
jkfjkl
==第3页==dkjsld
jlakcn
jkanck
lcahd;
;;;;;;
==第4页==;fklnc
mxznmz
,n,.zm
jiklas
djiaon
==第5页==akljkl
hjlhca
jcnlkn
la;/hj
agshyd
==第6页==gayuuw
qloetg
sywqiu
wujghb
ljksah
==第7页==uahis;
hy;aso
du;oui
opwd==第8页==

name 'printer' defined in class path resource [applicationContext.xml]: Error setting property value相关推荐

  1. 解决Error creating bean with name xxx defined in class path resource [applicationContext.xml]错误

    今天使用基于MapperFactoryBean来实现MyBatis与Spring的整合,使用Mapper接口编程,一直报一个错误,调试了很久 org.springframework.beans.fac ...

  2. Error creating bean with name ‘sqlSessionFactory‘ defined in class path resource [applicationContext

    学习spring框架时遇到一个问题,找了很久. 记录一个错误, D:\Java\jdk-14.0.2\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1 ...

  3. Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm

    报错信息如下: <span style="font-size:24px;">17:18:32,245 ERROR ContextLoader:307 - Context ...

  4. class path resource [applicationContext.xml] cannot be opened because it does not exis

    使用maven创建web工程,将spring配置文件applicationContext.xml放在src/resource下,用eclipse编译时提示class path resource [ap ...

  5. Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope

    1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContextat org.springframework.test ...

  6. 报错:IOException parsing XML document from class path resource [applicationContext.xml]; nested except

    1.出现IOException parsing XML document from class path resource [applicationContext.xml]; nested excep ...

  7. SSM中maven导入jar的报错问题(Line 1 in XML document from class path resource [applicationContext.xml] is ...)

    问题描述 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document f ...

  8. 遇到class path resource [applicationcontext.xml] cannot be opened becaus的问题该怎么解决??

    [applicationcontext.xml] cannot be opened becaus的问题该怎么解决? 本文旨在和小白一起成长,很不幸目前没有钱买idea,用了一段时间idea奈何到期了, ...

  9. java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened becaus

    今天在学Spring的时候遇到一个问题, 配置文件applicationContext.xml找不到,很是郁闷啊.文件明明在这,却找不到这种问题大多数是因为文件路径的不对引起的. 首先我的我的配置文件 ...

  10. IOException parsing XML document from class path resource [applicationContext.xml]

    今天在学习Spring框架时遇到了错误: 经过报错分析发现是applicationContext.xml文件位置放错了. 在本地测试时,applicationContext.xml文件应该放在src目 ...

最新文章

  1. 刘强东宣布: 未来京东将减员50%,每天工作3小时!无人公司来了……
  2. SpringBoot启动类的扫描注解的用法及冲突原则
  3. mysql路径查找_如何在MySQL的具有文件路径的列中查找和替换?
  4. javascript里的面向对象
  5. 女生适合做程序员吗?
  6. 抖音下拉框中的下拉词是怎么出来的?
  7. Spring Boot——开发新一代Spring应用
  8. 非因解读 | 单细胞空间蛋白质组分析技术揭示乳腺癌循环肿瘤细胞(CTC)与肿瘤异质性及肿瘤免疫的关系
  9. rms 公式 有效值_为什麼均方根值(RMS)比平均值表达好一些?
  10. CentOS6.5启动MariaDB错误
  11. 鹿晗关晓彤公开恋情,是如何把新浪微博的服务器搞垮的?
  12. vue : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\vue.ps1,因为在此系统上禁止运行脚本
  13. zoj 2975 Kinds of Fuwas(数学题)
  14. 1379690-01-3,3-Azido-D-alanine HCl结构式分享
  15. 第12集 关于库卡机器人对需要减速和插值方式说明
  16. 传说中让理科生沉默,让文科生落泪的文史综合题
  17. Mybatis关系映射一对一的关系
  18. 高德地图实现多点标注marker和动态信息窗体
  19. VM-虚拟机装苹果系统
  20. 中国中医医院竞争力排行榜500强:绵竹市中医医院

热门文章

  1. 考研-寒假日记(大三) ZERO
  2. Floyd佛洛伊德算法
  3. C# 控件的动画显示效果 导航栏动画 字体动画效果制作
  4. android运用反射打开数据漫游
  5. 阿里最新开源的这份“亿级流量”小册,涵盖了高并发的所有操作
  6. 米线店结账程序 装饰着模式_实验报告2 装饰者模式
  7. C语言入门-结构类型
  8. 拿什么与钉钉竞争?工作圈3.0老鱼试用手记
  9. win10+ubuntu18.04双系统在NVIDIA GTX1050 笔记本上的安装纪实
  10. 一个手机号就能泄露全部隐私?百度安全专家还原真相