Исключение org.springframework.beans.NotWritablePropertyException вызвано, но я не знаю, почему

я новенькая весной. и я учусь, но во время обучения я получаю ошибку. Я использую конфигурацию на основе XML для весны, и вот ошибка компиляции:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloGeorgia' defined in class path resource [Beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'werili' of bean class [com.tutorialspoint.HelloGeorgia]: Bean property 'werili' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

но я не могу понять почему.

вот файл bean.xml:

<?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-3.0.xsd">

    <bean id = "helloworld" class = "com.tutorialspoint.HelloWorld">
        <property name = "message" value = "Hello World" />
        <property name = "werili" value = "Hello Hello" />
    </bean>


    <bean id = "helloGeorgia" class = "com.tutorialspoint.HelloGeorgia" 
             parent = "helloworld">
        <property name = "message" value = "Hello Georgia" />
    </bean>
</beans>

и вот три java-файла: MainApp.java

package com.tutorialspoint;

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



public class MainApp {
    public static void main(String[] args){
        ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

        HelloWorld f = (HelloWorld) context.getBean("helloworld");
        System.out.println(f.getMessage());

        HelloGeorgia georgia = (HelloGeorgia) context.getBean("helloGeorgia");
        System.out.println(georgia.getMessage());

    }
}

HelloWorld.java

package com.tutorialspoint;


public class HelloWorld {
    private String message;
    private String werili;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getWerili() {
        return werili;
    }

    public void setWerili(String werili) {
        this.werili = werili;
    }
}

HelloGeorgia.java

package com.tutorialspoint;

public class HelloGeorgia {
    private String message;

    public String getMessage() {
        return message;

    }

    public void setMessage(String message) {
        this.message = message;
    }

}

пожалуйста, посоветуйте мне, как это исправить. Спасибо

0
0
63
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

посмотрите на вашу весеннюю конфигурацию helloGeorgia, как ожидается, будет потомком компонента helloWorld. Где, как в классе Java, это не так. Либо у вас должно быть наследование в java, либо, по крайней мере; вы должны объявить те же поля с геттером/сеттером в helloGeorgia.

Другие вопросы по теме