Use MyBeanPostProcessor class

MyBeanPostProcessor the implements the BeanPostProcessor {class public
    @Override
    public postProcessBeforeInitialization Object (Object the bean, the beanName String) throws BeansException {
        //System.out.println ( "Fifth step: before the initialization method ...");
        return the bean;
    }

    @Override
    public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
        //System.out.println("第八步:初始化后方法...");
        if("userDao".equals(beanName)){
            Object proxy = Proxy.newProxyInstance(bean.getClass().getClassLoader(), bean.getClass().getInterfaces(), new InvocationHandler() {
                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if("save".equals(method.getName())){
                        System.out.println("权限校验===================");
                        return method.invoke(bean,args);
                    }
                    return method.invoke(bean,args);
                }
            });

            return proxy;
        }else{
            return bean;
        }

    }
}

Guess you like

Origin blog.csdn.net/song_chengbo/article/details/97414840