美文网首页服务端
SpringBoot之CommandLineRunner使用

SpringBoot之CommandLineRunner使用

作者: snail_fei | 来源:发表于2020-10-28 16:51 被阅读0次
    /**
     * Interface used to indicate that a bean should <em>run</em> when it is contained within
     * a {@link SpringApplication}. Multiple {@link CommandLineRunner} beans can be defined
     * within the same application context and can be ordered using the {@link Ordered}
     * interface or {@link Order @Order} annotation.
     *
     * 接口被用作将其加入spring容器中时执行其run方法。多个CommandLineRunner可以被同时执行在同一个spring上下文中并且执行顺序是以order注解的参数顺序一致。
     *
     * If you need access to {@link ApplicationArguments} instead of the raw String array
     * consider using {@link ApplicationRunner}.
     * 如果你需要访问ApplicationArguments去替换掉字符串数组,可以考虑使用ApplicationRunner类。
     */
    

    CommandLineRunner接口 的Component 会在所有的Spring Beans 都初始化之后,SpringApplication.run() 之前执行,适合应用程序启动之初的数据初始化工作。


    image.png

    相关文章

      网友评论

        本文标题:SpringBoot之CommandLineRunner使用

        本文链接:https://www.haomeiwen.com/subject/emkcvktx.html