spring中的bean后处理器

package com.process;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.action.LoginAction;

public class FirstBeanPostProcess implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("bean后处理器在初始化bena"+beanName+"之前进行增强处理");
        return bean;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("bean后处理器在初始化bena"+beanName+"之后进行增强处理");
            if(bean instanceof LoginAction){
                LoginAction loginAction = (LoginAction)bean;
                loginAction.setTip("tiptipfrom beanpostprocess");
            }
        return bean;
    }

}

 

posted @ 2016-08-30 11:43  公众号java-codestack  阅读(945)  评论(0编辑  收藏  举报