sping第一个小程序报错bean property "helloword" is not writable 问题分析
来源:互联网 发布:离线写作软件 编辑:程序博客网 时间:2024/06/10 23:21
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'helloword' of bean class [HelloBean]: Bean property 'helloword' is not writable or has an invalid setter method. Did you mean 'helloWord'?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:751)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:608)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:970)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:729)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:416)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
at SpringDemo.main(SpringDemo.java:15)
源码:beans-config.xml
<bean id="HelloBean"
class="HelloBean">
<property name="helloword">
<value>Hello!</value>
</property>
</bean>
Helloword.java::
public class HelloBean {
private String helloWord;
public String getHelloWord() {
return helloWord;
}
public void setHelloWord(String helloWord) {
this.helloWord = helloWord;
}
}
SpringDemo.java::
public class SpringDemo {
public static void main (String[] args){
Resource rs = new ClassPathResource("beans-config.xml");
BeanFactory factory = new XmlBeanFactory(rs);
HelloBean hello = (HelloBean)factory.getBean("HelloBean");
System.out.println(hello.getHelloWord());
}
}
问题分析:SpringDemo.java 通过BeanFactory读取配置文件,HelloBean的实例依赖于Spring对象,通过setter所保留的接口,使用setter injection完成依赖注入,完成依赖的关系注入;BeanFactory读取Bean的配置设置并完成关系维护后,通过getbean()方法指定Bean的名称来获得Bean实例;需要注意的是:bean-config.xml里的 propery的name属性的值 helloword,需要与HelloBean.java的变量名称一致,才不会报上面的错。
- sping第一个小程序报错bean property "helloword" is not writable 问题分析
- dubbo-admin程序报错Bean property 'URIType' is not writable or has an invalid setter method.
- 报错:Bean property 'jdbcTemplate' is not writable or has an invalid setter method
- Spring 配置文件报错:Bean property 'xxx' is not writable or has an invalid setter method
- dubbo-admin-2.5.3 运行报错: Bean property 'URIType' is not writable or has an invalid,uritypewritable
- SSH框架 Bean property * is not writable or has an invalid setter method错误分析与解决方法
- resource required not found之Bean property 'sessionFactory' is not writable or has an invalid setter
- 第一个程序HelloWord
- Bean property 'loginDAO' is not writable or has an invalid setter method
- Bean property 'service' is not writable or has an invalid setter method. Did you mean 'serivce'?
- Bean property 'xxx' is not writable or has an invalid setter method
- 错误信息:Bean property 'sessionFactory' is not writable or has an invalid setter method.
- Bean property 'annotatedClasses' is not writable or has an invalid setter method
- Bean property 'adminService' is not writable or has an invalid setter method
- Bean property XX' is not writable or has an invalid setter method
- spring中XML中Bean property 'dataSource' is not writable or has an invalid setter method.
- Bean property 'xxx' is not writable or has an invalid setter method
- 错误信息:Bean property 'sessionFactory' is not writable or has an invalid setter method.
- C++实现双链表
- 自己收集的学习资源
- VS使用技巧
- 关于视频录制预览摄像头拉伸问题
- tensorflow目录结构
- sping第一个小程序报错bean property "helloword" is not writable 问题分析
- 深入分析JDBC超时机制
- 347. Top K Frequent Elements
- (一)数据库事务-事务的特性
- Python程序提示SyntaxError: invalid syntax错误
- C
- C语言写CGI程序
- redis 五大数据结构介绍
- 第八届福建省大学生程序设计竞赛训练总结【7/12】