org.springframework.beans.NotWritablePropertyException

Spring属性注入异常

错误信息:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'brand ' of bean class [com.smart.injection.Car]: 

Bean property 'brand ' is not writable or has an invalid setter method. Did you mean 'brand'?

相关配置文件:

<?xml version="1.0"encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<!--属性注入-->

    <bean id="car"class="com.smart.injection.Car">

        <property name="brand
"><value>红旗CA72</value></property>

        <property name="maxSpeed"><value>200</value></property>

    </bean>

</beans>

排查过程:

    检查配置文件是否对应、属性名是否正确、是否有网上所说的setter方法。结果均正确,brand是String类型,将其value值“红旗CA72”加上引号依旧报错。

最终解决方案:

    眼尖一点,就会发现,配置文件中<property name="brand
">的brand多了一个空格,删掉多余空格就OK。泪崩啊

时间: 2024-11-29 05:09:06

org.springframework.beans.NotWritablePropertyException的相关文章

做spring2.5+jpa整合时,出现org.springframework.beans.NotWritablePropertyException,请高手指教

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'entityManagerFactory'definedinclasspathresource[applicationContext.xml]:Errorsettingpropertyvalues;nestedexceptionisorg.springframework.beans.NotWritablePropertyEx

org.springframework.beans.NotWritablePropertyException:求解决

问题描述 XML code(applicationContext.xml)<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <!-- com.mchange.v2.c3p0.ComboPooledDataSource --> <!-- 指定连接数据库的驱动 --> <

springmvc-org.springframework.beans.factory.BeanCreationException:

问题描述 org.springframework.beans.factory.BeanCreationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [application.xml]: Error setting property values; nested

求解:org.springframework.beans.factory.BeanCreationException

问题描述 配置文件<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframew

跪求大神帮解决org.springframework.beans.factory.BeanCreationException: Error creating b

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0':Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.Be

Spring-Bean的初始化(init方法和实现org.springframework.beans.factory.InitializingBean接口)

init()方法 在BEAN中增加一个方法inti(),用来完成初始化工作(去掉构造函数) 然后修改配置文档config.xml,指定Bean中要初始化的方法, 最后编写测试程序 Bean package com.gc.action; import java.util.Date; public class HelloWorld { private String msg=null;//该变量用来存储字符串 private Date date=null;//该变量用来存储日期 // public H

nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException

You should autowire interface AbstractManager instead of class MailManager. If you have different implemetations of AbstractManager you can write @Component("mailService") and then @Autowired @Qualifier("mailService") combination to au

javase-关于Myeclipse的错误org.springframework.beans.factory.BeanCreationException

问题描述 关于Myeclipse的错误org.springframework.beans.factory.BeanCreationException 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreati

ibatis和Spring整合抛org.springframework.beans.factory.BeanCreationException

问题描述 『spring2.5和Ibatis2整合』spring配置文件如下:<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://