@value in Spring 3.0

Source: Internet
Author: User

In Spring 3.0, you can use @value for some files such as Xxx.properties
The following are examples of key-value pairs that are injected into the file:

1 First add in Applicationcontext.xml:
<beans xmlns:util= "Http://www.springframework.org/schema/util"
xsi:schemalocation= "Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/ Spring-util-3.1.xsd ">
</beans>

namespace, and then

2
<util:properties id= "Settings" location= "Web-inf/classes/meta-inf/spring/test.properties"/>

3 Creating Test.properties
Abc=123

4
Import Org.springframework.beans.factory.annotation.Value;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping ("/admin/images")
@Controller
public class Imageadmincontroller {

Private String Imagedir;
@Value ("#{settings[' Test.abc '}")
public void Setimagedir (String val) {
This.imagedir = val;
}


}
This will inject the value of TEST.ABC into the imagedir.

@value in Spring 3.0

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.