我們在之前的文章中簡單的說過SpringBoot的CommandLineRunner和ApplicationRunner這兩個接口
接口。在org.springframework.boot.SpringApplication#run()這個方法中有這樣一段代碼:
方法内容如下:
SpringBoot的注釋中說,在上下文重新整理完之後調用這個方法。在調用這個方法的時候Spring容器已經啟動完
成了。這裡的context的真正對象是:AnnotationConfigEmbeddedWebApplicationContext,這個類貫
穿着SpringBoot的整個啟動過程。我們看一下callRunners這個方法的内容:
callRunner方法的内容就很簡單了直接調用run方法。
ApplicationRunner和CommandLineRunner的差別就是run方法參數不同,ApplicationRunner中run方法
的參數是ApplicationArguments,CommandLineRunner中run方法的參數是String類型的可變參數。。