Brief analysis of Propertyplaceholderconfigurer class __ frame under spring frame

Source: Internet
Author: User
To understand this class, the first thing to figure out is a concept: Bean factory Post-processor
The official explanation is this:
A bean factory Post-processor is a Java class which implements the
Org.springframework.beans.factory.config.BeanFactoryPostProcessor interface. It is executed manually (in the case of the Beanfactory) or automatically (in the case of the ApplicationContext) to APPL Y changes of some sort to a entire beanfactory after it has been.
I understand the meaning of this:
1. First, the Bean factory Post-processor implements the Org.springframework.beans.factory.config.BeanFactoryPostProcessor interface.
2. In the case of beanfactory it is executed manually.
3. It will be executed automatically under the condition of ApplicationContext.
4. The most critical point is that the entire beanfactory is modified after an instance of the class is constructed.
So the Propertyplaceholderconfigurer class is one of the Bean Factory Post-processor, which is the configuration of a resource property, The ability to place the contents of a beanfactory definition in a file with a. propertis suffix.
For example
<bean id= "DataSource" class= "Org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name= "Driverclassname" ><value>${driver}</value></property>
<property name= "url" ><value>jdbc:${dbname}</value></property>
</bean>
and the actual Jdbc.propertis file is
Jdbc.driverclassname=org.hsqldb.jdbcdriver
jdbc.url=jdbc:hsqldb:hsql://production:9002
Jdbc.username=sa
Jdbc.password=root
And how Jdbc.propertis is quoted:
---spring-context.xml----
<bean id= "Propertyconfigurer" class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name= "Locations" >
<list>
<value>/WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
Register the top section configuration in Web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</context-param>
Of course, don't forget the spring listener registration
<listener>
<listener-class>
Org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
In this way, a simple data source is set up.
In fact, the role of Propertyplaceholderconfigurer is to place the database configuration information that the placeholder points on in the bean to define
of tools.
Welcome to criticize the master.

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.