Implements the Key-value in the spring Auto-injection properties file.
1. In the Applicationcontext.xml configuration file, introduce the <util/> namespace.
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.0.xsd ">
2, configure the annotation component Scan, with annotations to automatically inject
<base-package= "Com.packagename"></Context: Component-scan>
3. Create a property file under the Classpath path, such as Sys.properties
Test=sysdata
4. Let spring load the properties file and configure it in Applicationcontext.xml
<id= "sys" location= "Classpath:sys.properties"/>
5. Create a Java file and let spring inject the value of the property read from the resource file as follows
@Component Public class sysconf { @Value ("#{sys.test}") private String test; @Value ("#{sys.test}") publicvoid settest (String test) { = test; } @Value ("#{sys}") publicvoid setsysconf (Properties sys) { Test= Sys.getproperty ("test"); } }
Note: The #{sys} here corresponds to the Id=sys of the fourth step
Spring Auto-inject properties file