java 春季无效的属性异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1754171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:50:09  来源:igfitidea点击:

Invalid property exception in spring

javaspring

提问by Pratik Garg

I am using spring in my application , When i am loading the springApplicationContext to get the beans i am getting the errors

我在我的应用程序中使用 spring,当我加载 springApplicationContext 以获取 bean 时,我收到错误

Caused by: org.springframework.beans.InvalidPropertyException: Invalid property "abc"

引起:org.springframework.beans.InvalidPropertyException:无效的属性“abc”

Even though there is a property abcand the setter for that property in the bean.

即使abcbean 中有一个属性和该属性的设置器。

This is a weird error i know , but i can't figure out where is the problem.

我知道这是一个奇怪的错误,但我不知道问题出在哪里。

Any pointers will be helpful.

任何指针都会有所帮助。

Thanks! Pratik

谢谢!普拉蒂克

回答by BalusC

Ensure that the property has both a public setter and getter. In case of an AnyObjectproperty it should look like:

确保该属性同时具有公共 setter 和 getter。如果是AnyObject属性,它应该如下所示:

private AnyObject abc;
public AnyObject getAbc() { return abc; }
public void setAbc(AnyObject abc) { this.abc = abc; }

There is however one special case: in case of a booleanproperty it should look like:

然而,有一种特殊情况:如果是boolean属性,它应该如下所示:

private boolean abc;
public boolean isAbc() { return abc; }
public void setAbc(boolean abc) { this.abc = abc; }

Note the isprefix instead of get.

注意is前缀而不是get

回答by denis.zhdanov

I remeber the similar question at Spring forums. It was found out that there was a setter signature like

我记得 Spring 论坛上的类似问题。发现有一个 setter 签名,如

public class MyClass {

    private Aggregated field;

    public MyClass setField(Aggregated field) {
        this.field = field;
    }
}

I.e. the setter's return type was not void.

即 setter 的返回类型不是void

Anyway, Spring uses standard Instrospectorfor processing class properties. Try it with your class and check if target property is found.

无论如何,Spring 使用标准的Instrospector来处理类属性。与您的班级一起尝试并检查是否找到了目标属性。