Getting Started 16 - BeanFactoryPostProcessor Interface
Write the bean defined file usually use XML to write, XML class-type organizations are very convenient for various elements and attribute settings, but the XML file is always costly, especially in the document is full of many Define the content. For programs, some options usually do not change after setting, and some options may be adjusted at any time. At this time, if you can provide a more concise setup, some common options are available at any time. Such a program will be more flexible when used. We can provide this feature on org.springframework.beans.factory.config.beanfactoryPostProcessor interface:
BeanfactoryPostProcessor.java
Public interface beanfactoryPostProcessor {
Public void PostProcessBeanFactory (ConfigurableListableBeanFactory Beanfactory) throws beansexception;
}
From the name of the BeanFactoryPostProcessor interface, you can know the bean of this interface, you can do some subsequent processing actions after BeanFactory completed dependencies, what to do will depend on you, for example, we can complete the dependence in Beanfactory, according to One simple properties file we provide to set some other options. However, Spring has provided us with a HomeFactoryPostProcessor: org.springframework.beans.Factory.config.PropertyPlaceHolderConfigurer. Let's take a look at the actual example of a bean defined file:
XML Version = "1.0" encoding = "UTF-8"?>
Property>
bean>
Property>
....
bean>
......
beans>
Assuming that there are many dependent properties in Hellobean, these are more uncommon-changing properties, and HelloWord changes frequently, we can simply set through Hello.properties:
Hello.properties
HelloWord = Hello! Justin! PropertyPlaceHolderConfigure reads the property file set by Loc, and sets the HelloWord value to $ {helloword} to complete dependency injection. Another case is that some low-programs can be set in the XML definition file, but the high-relief program administrators can override the settings of the low-rights programs through the attribute file settings. To complete the unity of high-relocation management, Spring also provides such beanFactoryPostProcessor's actual category: org.springframework.beans.factory.config.propertyoverrIDeconfigurer. Take a look at how the bean definition is set:
XML Version = "1.0" encoding = "UTF-8"?>
Property>
bean>
Property>
....
bean>
....
beans>
In this bean definition file, although Hellobean has set a HelloWord property, high-level managers can use a Hello.Properties to overthrow this setting:
Hello.properties
Hellobean.Helloword = Hello! Justin!
The above specified HelloBean property helloWord is Hello! Justin!