org.springframework.beans.NotWritablePropertyException

简介: <div style="font-family:微软雅黑; font-size:14px; line-height:21px; widows:auto"> <div style="background-color:inherit">Spring属性注入异常</div> <div style="background-color:inherit"><br style="background
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。泪崩啊



目录
相关文章
|
6月前
|
Java
SpringBoot注入出现@org.springframework.beans.factory.annotation.Autowired(required=true)
SpringBoot注入出现@org.springframework.beans.factory.annotation.Autowired(required=true)
78 0
|
6月前
|
容器
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
|
6月前
解决The injection point has the following annotations:@org.springframework.beans.factory.annotation错误~
解决The injection point has the following annotations:@org.springframework.beans.factory.annotation错误~
970 0
|
12月前
解决:org.springframework.web.method.annotation.MethodArgumentTypeMismatchExceptio
解决:org.springframework.web.method.annotation.MethodArgumentTypeMismatchExceptio
450 0
|
存储 安全 Java
初识springframework
初识springframework
|
开发框架 Java 数据库连接
SpringFramework初识
SpringFramework初识
SpringFramework初识
|
Java 数据库连接 Maven
NoSuchMethodError: org.springframework.beans.factory.config.BeanDefinition.getResolvableType()Lorg/s
Spring整合Mybatis时出现错误:NoSuchMethodError:org.springframework.beans.factory.config.BeanDefinition.getResolvableType()Lorg/springframework/core/ResolvableType;及解决办法
NoSuchMethodError: org.springframework.beans.factory.config.BeanDefinition.getResolvableType()Lorg/s
|
Java Spring 开发者
|
网络安全
SSH框架整合遇到的错误——org.springframework.beans.NotWritablePropertyException:
提示错误信息: Unable to instantiate Action, userAction, defined for 'user_registPage' in namespace '/'Error creating bean with name 'userAction' defined in class path resource [applicationContext.
1634 0
Aurora-hec4.0_scaninvoice_异常_04_org.springframework.beans.factory.BeanNotOfRequiredTypeException
    二、参考资料 1.解决: org.springframework.beans.factory.BeanNotOfRequiredTypeException办法 2.
921 0