接rocketMQ的consumerMessageHook时遇到了一个生命周期位置的问题
这里写了一个小demo验证下生命周期
打印顺序
LifeCycleTest 实例化
LifeCycleTest setName:lifeCycleTest
LifeCycleTest setApplicationContext
LifeCycleTest afterPropertiesSet
LifeCycleTest afterSingletonsInstantiated
LifeCycleTest isRunning
LifeCycleTest start
停止服务时
LifeCycleTest isRunning
LifeCycleTest stop
LifeCycleTest destroy
@Component public class LifeCycleTest implements SmartInitializingSingleton, SmartLifecycle, InitializingBean, DisposableBean, BeanNameAware, ApplicationContextAware { boolean isRunning = false; public LifeCycleTest() { System.out.println("LifeCycleTest 实例化"); } @Override public void setBeanName(String s) { System.out.println("LifeCycleTest setName:" + s); } @Override public void destroy() throws Exception { System.out.println("LifeCycleTest destroy"); } @Override public void afterPropertiesSet() throws Exception { System.out.println("LifeCycleTest afterPropertiesSet"); } @Override public void afterSingletonsInstantiated() { System.out.println("LifeCycleTest afterSingletonsInstantiated"); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { System.out.println("LifeCycleTest setApplicationContext"); } @Override public void start() { isRunning = true; System.out.println("LifeCycleTest start"); } @Override public void stop() { System.out.println("LifeCycleTest stop"); } @Override public boolean isRunning() { System.out.println("LifeCycleTest isRunning"); return isRunning; } }
乐享:知识积累,快乐无限。