我现在是春天的新人.我试图遵循调用PostConstruct和BeanPostProcessor的顺序.
据我所知,下面是订单: -
BPP - > postProcessBeforeInitialization
PostContruct
BPP - > postProcessAfterInitialization
但是我看到以下顺序: -
PostContruct
BPP - > postProcessBeforeInitialization
PostContruct
BPP - > postProcessAfterInitialization
SpringConfig文件foo.xml删除了bean标记上下文:component-scan base-package ="springtest"
@Component public class MySpring implements ApplicationContextAware,BeanPostProcessor{ public static int temp =0; public MySpring(){ System.out.println("Initializing MySpring Constructor"); } @PostConstruct public void temp(){ System.out.println("PostConsturct" + this.getClass()); temp++; } public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { System.out.println("Before BPP " + bean.getClass()); return this; } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("After BPP " + bean.getClass()); return this; } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { System.out.println("Initializing ApplicationContext"); }}
响应
初始化MySpring构造函数
初始化ApplicationContext
PostConsturctclass springtest.MySpring
属性设置类springtest.MySpring后
在BPP类之前org.springframework.context.event.EventListenerMethodProcessor
PostConsturctclass springtest.MySpring
属性设置类springtest.MySpring后
在BPP类springtest.MySpring之后
在BPP类之前org.springframework.context.event.DefaultEventListenerFactory
PostConsturctclass springtest.MySpring
属性设置类springtest.MySpring后
在BPP类springtest.MySpring之后
MySpring.temp值为3表示PostContruct是calles 3次.
有人可以帮助我以上......