Prompt invalid setter method, invalidsetter when spring injects static member variables

Source: Internet
Author: User

Prompt invalid setter method, invalidsetter when spring injects static member variables

It was not very careful enough to get stuck for one night ..

It is an extremely simple small program, but a value needs to be injected through the xml file configuration. The unique attribute, especially the static member variable in the class, is used ..

And then the get and set methods are automatically generated...

Public class Food {private static String desc; public static String getDesc () {return desc;} public static void setDesc (String desc) {Food. desc = desc ;}}

Then, configure the following in xml:

<Bean id = "food" class = "xxxk. Food"> <property name = "desc" value = "food"/> </bean>

Then, the system will report an error where the set method cannot be found... compare the name of the set Method repeatedly, without any exception... then it will be decommissioned one night...

Finally, it is found that the automatically generated method will contain the static modifier, while the spring set method cannot be static. Let's look at the source code to find that although various values and names can be obtained, however, one of the resolvedDescriptor cannot be obtained.

Remove the static modifier before the set method ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.