特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过。如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:
http://www.cnblogs.com/mao2080/
1、问题描述
在排查rabbitmq消息堆积问题时,单独将自己封装的SDK拿出来发现死活都注册不上去,结果发现是启动顺序导致的,需要实现ApplicationListener接口。
2、解决方案
1、实现ApplicationListener
1 @Component 2 public class MyListener implements ApplicationListener<ApplicationReadyEvent> { 3 4 public void onApplicationEvent(ApplicationReadyEvent arg0) { 5 System.out.println("Spring容器启动好了..."); 6 } 7 8 }
1 @Component 2 public class Runner implements CommandLineRunner{ 3 4 @Override 5 public void run(String... strings) throws Exception { 6 System.out.println("CommandLineRunner..."); 7 } 8 9 }