spring BeanFactoryPostProessor接口

当BeanFactory加载Bean定义文件的所有内容,但还没正式产生Bean实例之前,
需要对BeanFactory进行处理的话,可以实现BeanFactoryPostProessor接口的postProcessBeanFactory方法来完成,今天记录几个spring提供的几个实现类及其发挥的作用
1.PropertyPlaceholderConfigurer
提供读取.properties文件中的内容供spring配置文件中使用,依赖属性 location为配置文件
路径

<bean id="configBean" class="org.springframework.beans.factory.
     config.PropertyPlaceholderConfigurer">
  <property name="location">
    <list>
      <value>test.properties</value>
    </list>
  </property>
</bean>


2.PropertyOverrideConfigurer
提供.properties文件对配置文件Bean属性的设定,如果Bean属性已有注入将会被.properties文件中声明的所覆盖,.properties中执行指定beanId.property=value就可以对该bean的属性进行赋值

3.CustomEditorConfigurer
设定注入bean的自定义方法,方法类需要实现PropertyEditorSupport,属性customEditors来设定需要被注入的bean类型的map

<bean id="configBean" class="org.springframework.beans.factory.
     config.CustomEditorConfigurer">
  <property name="customEditors">
    <map>
      <entry key="...."><bean 自定义方法类></entry>
    </map>
  </property>
</bean>

猜你喜欢

转载自sdh88hf.iteye.com/blog/1024390