A Beanfactorypostprocessor class is provided for you in the Spring framework: Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer. With this class, you can move some configuration settings out of the to. properties file, and the. properties file can be used as a customer to customize some relevant parameters as required.
Look at a real example of a bean definition file:
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/s Pring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/co Ntext/spring-context-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/ao P/spring-aop-3.0.xsd "> <bean id=" propertyconfigurer "class=" Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "> <property name=" fileencoding " Value= "GBK"/> <property name= "Locations" > <list> <value>classpath:mailsender.properties</value> </list> </property> </bean> <bean id= "Javamailsender" class= "or G.springframework.mail.javamail.javamailsenderimpl "> <property name=" host "> <value>${mail.host} </value> </property> <property name= "Port" > <value>${mail.port}</value> </proper ty> <property name= "javamailproperties" > <props> <prop key= "Mail.smtp.auth" &
gt;false</prop> <prop key= "Mail.smtp.timeout" >25000</prop> </props> </property> <property name= "username" > <value>${mail.username}</value> </PROPERTY&G
T <property name= "Password" > <value>${mail.password}</value> </property> </bean> </b Eans>
This is an email demo (but this article is not about how to send the mail, but to take it out as an example),
There are many properties of dependency injection in MailSender, these are relatively infrequently changing attributes, but his values may often change, and sometimes customer needs need to change, Can be simply set through mailsender.properties, and this information is set in the Location attribute:
Mail.transport.protocol=smtp
Mail.host=stmp.qq.com
Mail.port=25
Mail.username=xxxxxxxx@qq.com
Mail.password=xxxxxxxx
You can get these dynamically by configuring the Propertyplaceholderconfigurer bean. Properties in a property file, which is very handy for a configuration file that needs to change frequently.
If you have more than one. properties file, you can set it by using the Locations property.
<property name= "Locations" >
<list>
<value>classpath:mailsender1.properties</value> <value>classpath:mailsender2.properties</ Value>
</list>
</property>