zoukankan      html  css  js  c++  java
  • 应用程序启动后首先被调用CommandLineRunner

    public void run(String... args),最重要的是:这个方法会在应用程序启动后首先被调用
    那种只需要在应用程序启动时执行一次的任务,非常适合利用Command line runners来完成。
    Spring Boot应用程序在启动后,会遍历CommandLineRunner接口的实例并运行它们的run方法。
    也可以利用@Order注解(或者实现Order接口)来规定所有CommandLineRunner实例的运行顺序。
     
    例子:
     1 @EnableAsync
     2 @EnableSwagger2Doc
     3 @SpringBootApplication
     4 public class App implements CommandLineRunner,Common{
     5     @Autowired
     6     private ApplicationContext appContext;
     7     
     8     public static void main(String[] args) throws Exception {
     9         Logger.info("Server Loading Start:");
    10         /**
    11          * mybatis初始化
    12          */
    13         DbCache.instance();
    14         
    15         DataCache.init();
    16 
    17         /**
    18          * *开启service服务
    19          */
    20         SpringApplication.run(App.class, args);
    21         
    22         Logger.info("Server Loading end:");
    23         
    24     }
    25     
    26     @Override
    27     public void run(String... args) throws Exception {
    28         String[] beans = appContext.getBeanDefinitionNames();
    29         for (String bean : beans) {
    30             HttpInterface.loadInterface(appContext.getBean(bean).getClass());
    31         }
    32     }
    33 }
  • 相关阅读:
    【javaSE】Exception in thread "main" java.lang.ArrayStoreException: java.lang.Integer
    property
    多继承与super
    GIL全局解释器锁
    深浅拷贝
    生成器
    迭代器
    设置ll命令
    修改Centos中的ll命令(以 K 为单位显示文件大小)
    打包解压缩命令
  • 原文地址:https://www.cnblogs.com/YangBinChina/p/13784911.html
Copyright © 2011-2022 走看看