The Propertyplaceholderconfigurer role in spring, usage

Source: Internet
Author: User
Tags aop configuration settings
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> &LT;/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>


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.