beanPostProccess实现类DefaultAdvisorAutoProxyCreator 实现AOP
@Bean public DefaultPointcutAdvisor defaultPointcutAdvisor(){ NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); pointcut.addMethodName("test"); DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor(); defaultPointcutAdvisor.setPointcut(pointcut); defaultPointcutAdvisor.setAdvice(new ZhouyuAfterReturningAdvise()); return defaultPointcutAdvisor; } @Bean public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); return defaultAdvisorAutoProxyCreator; }
通过DefaultAdvisorAutoProxyCreator会直接去找所有Advisor类型的Bean,根据Advisor中的 PointCut和Advice信息,确定要代理的Bean以及代理逻辑。 但是,我们发现,通过这种方式,我们得依靠某一个类来实现定义我们的Advisor,或者Advise,或 者Pointcut,那么这个步骤能不能更加简化一点呢?