特別提示:本人博客部分有參考網絡其他博客,但均是本人親手編寫過並驗證通過。如發現博客有錯誤,請及時提出以免誤導其他人,謝謝!歡迎轉載,但記得標明文章出處:
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 }