The first thing to do is to build the spring MVC environment and then start the configuration in the properties file:
First step: Inject the properties into the Springcontext, the specific path to adjust itself
<BeanID= "config"class= "Org.springframework.beans.factory.config.PropertiesFactoryBean"> < Propertyname= "Locations"> <List> <value>Classpath:config.properties</value> </List> </ Property> < Propertyname= "fileencoding"value= "Utf-8" /></Bean>
Step Two: Add value annotations at the place of use
@Value ("#{config[' Email.hostname '}")private String hostName; @Value ("#{config[" Email.address ']} ")private String address;
Step three: Using Attributes
System.out.println (HostName); SYSTEM.OUT.PRINTLN (address);
Attached config.properties:
# #配置email. hostName=smtp.aliyun.comemail.address[email protected]
Using the properties file in Spring MVC