实现:
之前 代理对象 的生成 是在 Bean对象创建之前,即不在 Bean 的生命周期,无法实现属性的注入,现在需要调整其生成时机,整个流程其实十分简单,迁移 之前 AOP代理方法 到 BeanPostProcessor 的 postProcessAfterInitialization 的方法,这样在 bean 属性注入并初始化之后,就会调用 其代理方法来完成 AOP 代理。
Tip:因为此时 代理对象的生成 是在 Bean实例化之后,所以 DefaultAdvisorAutoProxyCreator 配置 TargetSource 需将 targetSource = new TargetSource(beanClass.getDeclaredConstructor().newInstance()); 修改为 targetSource = new TargetSource(bean); ,否则将代理新的实例化对象,从而导致属性无法注入。
