1. 程式人生 > >CommandLineRunner或ApplicationRunner介面

CommandLineRunner或ApplicationRunner介面

前言

CommandLineRunner和ApplicationRunner介面是在容器啟動成功後的最後一步回撥。

CommandLineRunner介面

介面被用作將其加入spring容器中時執行其run方法,多個CommandLineRunner可以被同時執行在同一個spring上下文中並且捃順序是以order註解的引數順序一致。

ApplicationRunner介面

以上面介面的javadoc一樣,區別在於接收的引數不一樣。CommandLineRunner引數是最原始的引數,沒有做任何處理。ApplicationRunner的引數是ApplicationArguments,是對原始引數做了進一步封裝。