关于我是小白这件事 2022-01-20 22:09 采纳率: 66.7%
浏览 51
已结题

NotWritablePropertyException错误

问题遇到的现象和发生背景

发现NotWritablePropertyException

public class Person {
    private Integer age;

    public Person() {
    }

    public Person(Integer age) {
        this.age = age;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {    this.age=age;}

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}


<?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="person01" class="com.ww.Person">
        <property name="age" value="21"></property>
    </bean>
</beans>


package com.ww;


import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Person {
    @Test
    public void test1(){
        ApplicationContext ioc =
                new ClassPathXmlApplicationContext("ioc.xml");
        Person bean = (Person) ioc.getBean("person01");
        System.out.println(bean.getClass());
        
    }
}
问题相关代码,请勿粘贴截图

感觉是xml连接不上Person

运行结果及报错内容

at com.ww.Person.test1(Person.java:11)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'age' of bean class [com.ww.Person]: Bean property 'age' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

  • 写回答

2条回答 默认 最新

  • rjyb22 2022-01-21 09:51
    关注

    类重名,

    img

    img

    img


    ioc配置文件配置的是这个同名测试类

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月29日
  • 已采纳回答 1月21日
  • 创建了问题 1月20日

悬赏问题

  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟