Spring@value several cases where a value is not being taken

Source: Internet
Author: User
One, the spring component overrides the constructor method, and reference @value in the constructor method is null
Because the spring instantiation order is the first to execute the constructor method and then inject the member variable, the order is to execute the construction method first and then inject the member variable, so the ING instantiation value is null
The workaround is to write a constant class, refer to @value in the constant class, and then reference the variable of the constant class in the constructor method.

Second, use the new object when calling the spring component instead of @autowired

Third, use final or static modifier member variable

Four, the reference @value in spring MVC is null
Spring MVC is a child container of spring and requires a configuration file to be imported in two configuration files
<context:property-placeholder location= "Classpath:jdbc.properties" ignore-unresolvable= "true"/>

[email protected] several cases where the value cannot be taken

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.