To reference the properties or to configure in XML, there are two configuration methods for referencing a single properties file, and multiple properties files
One, read a single properties file
In the spring configuration file, add the
Introduce the until 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 "
Read the Properties file
<util:properties id= "Propertiesreader" location= "Classpath:test.properties"/>
Second, read multiple properties files
<bean id= "Propertiesreader"
class= "Org.springframework.beans.factory.config.PropertiesFactoryBean" >
<property name= "Locations" >
<list>
<value>classpath:param.properties</value>
<value>classpath:base.properties</value>
</list>
</property>
</bean>
Both methods are actually the same.
Read the Properties file property in the class
The properties that need to be injected in the class implement setter and Getter methods.
Add @Value annotations before the setter method
@Value ("#{propertiesreader[propertiesname]}")
Propertiesname is the key in the properties file. In this way, Spring will automatically inject values during the container startup process.