List of usage examples for org.springframework.aop.framework ProxyFactoryBean setBeanFactory
@Override public void setBeanFactory(BeanFactory beanFactory)
From source file:com.ivanzhangwb.interpose.core.InterposeBootStrap.java
@Override public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException { if (interposeClassPathApplicationContext == null) { interposeClassPathApplicationContext = new InterposeClassPathApplicationContext( this.applicationContext); }/*from w w w.ja va 2 s .co m*/ boolean needInterpose = false; Class beanClass = bean.getClass(); do { Method[] methods = beanClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (Interpose.class != null && methods[i].isAnnotationPresent(Interpose.class) && methods[i].equals(ClassUtils.getMostSpecificMethod(methods[i], bean.getClass()))) { needInterpose = true; handleMethodAnnotation(methods[i]); } } beanClass = beanClass.getSuperclass(); } while (beanClass != null); if (needInterpose) { ConfigurableApplicationContext atx = (ConfigurableApplicationContext) interposeClassPathApplicationContext; DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) atx.getBeanFactory(); ProxyFactoryBean factoryBean = new ProxyFactoryBean(); factoryBean.setTarget(bean); factoryBean.setInterceptorNames(new String[] { InterposeConstants.INTERPOSE_CORE_INTERCEPTOR }); factoryBean.setBeanFactory(beanFactory); return factoryBean.getObject(); } else { return bean; } }