美文网首页
SpringBoot之ApplicationRu

SpringBoot之ApplicationRu

作者: 但时间也偷换概念 | 来源:发表于2019-01-05 17:54 被阅读0次

    简介:

    CommandLineRunner、ApplicationRunner 接口是在容器启动成功后的最后一步回调(类似开机自启动)。

    使用:

    CommandLineRunner的使用,编写一个类去实现CommandLineRunner接口,并覆写run方法,即可接入Spring观察者模式的回调功能,完成自己在容器启动成功之后想做的事情。

    ApplicationRunner 和CommandLineRunner的区别只是在于接收的参数不一样。CommandLineRunner的参数是最原始的参数,没有做任何处理。ApplicationRunner的参数是ApplicationArguments,是对原始参数做了进一步的封装。

    CommandLineRunner ApplicationRunner

    如上图,ApplicationRunner 和 CommandLineRunner均支持多个监听,所以可以使用@Order注解去指定监听器执行链的执行顺序,它会按@Order注解指定的顺序依次执行你的回调。

    相关文章

      网友评论

          本文标题:SpringBoot之ApplicationRu

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