当我们使用Spring容器管理对象时,需要对对象进行一些后期处理时,比如数据处理、数据预加载,可以使用BeanPostProcessor接口。
简单演示它的用法。
定义扫描包,显示定义BeanPostProcessor的实现类:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- scan the component from the base package --> <context:component-scan base-package="com.nicchagil.springapplication.No004BeanPostProcessor" /> <bean /> </beans>