很多人学Spring框架,总觉得IOC模糊不清?( 三 )

/**    拦截实例化之后的对象(实例化了 并且属性注入了)    拦截所有的 */@Componentpublic class MyBeanPostProcessor implements BeanPostProcessor {    @Override    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {        if ("lazyResult".equalsIgnoreCase(beanName)){            System.out.println("MyBeanPostProcessor before");        }        return bean;    }    @Override    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {        if ("lazyResult".equalsIgnoreCase(beanName)){            System.out.println("MyBeanPostProcessor After");        }        return bean;    }}//XML配置文件中:    <bean id="lazyResult" class="com.lagou.edu.pojo.Result"  init-method="initMethodTest"></bean>//测试:    @org.junit.Test    public void testBeanLazy(){        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");        Object lazyResult =  applicationContext.getBean("lazyResult");        System.out.println(lazyResult);        applicationContext.close();    }打印出:

很多人学Spring框架,总觉得IOC模糊不清?

文章插图
 
4. 其他:
很多人学Spring框架,总觉得IOC模糊不清?

文章插图




推荐阅读