zoukankan      html  css  js  c++  java
  • springboot-15-启动时加载数据的方法CommandLineRunner

    有时需要爱项目启动时, 去加载一些配置文件什么的, 可以使用监听器的方式加载, 这是可以通过实现接口 CommandLineRunner来实现需求: 

    Spring Boot应用程序在启动后,会遍历CommandLineRunner接口的实例并运行它们的run方法。也可以利用@Order注解(或者实现Order接口)来规定所有CommandLineRunner实例的运行顺序。

    package com.iwhere.run;
    
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.core.annotation.Order;
    import org.springframework.stereotype.Component;
    
    /**
     * 该类可以在springboot启动是, 进行操作
     * @Order: 启动时执行的顺序, 小的优先执行
     * @author wenbronk
     * @time 2017年4月6日  下午1:40:17  2017
     */
    
    @Component
    @Order(value=2)
    public class MyStartupRunner implements CommandLineRunner {
    
        /**
         * 执行的方法,
         * args为执行时传入的参数, 
         * 可用: SpringApplication.run(App.class, new String[]{"hello,","林峰"});
         * 或者: eclipse中给java应用传args参数的方法如下:
                1、先写好Java代码,比如文件名为IntArrqy.java;
                2、在工具栏或菜单上点run as下边有个Run Configuration;
                3、在弹出窗口点选第二个标签arguments;
                4、把你想输入的参数写在program argumenst就可以了,多个参数使用空格隔开。
                完成后点run即可通过运行结果看到参数使用情况了。
         */
        @Override
        public void run(String... arg0) throws Exception {
            System.out.println("开机服务执行的操作....");
        }
    }

    原文地址: http://412887952-qq-com.iteye.com/blog/2292577

  • 相关阅读:
    layDate关闭方法
    iOS Crash日志符号化
    图像压缩工具ImageOptim介绍
    UITextField设置光标位置
    Detect backspace in UITextField
    scrollsToTop小结
    查看UIWindows的视图层次
    弹出框适配总结
    关于IOS获取keyBoard键盘是否弹出
    UItableViewCell滑动删除时,调整cell子视图的位置大小
  • 原文地址:https://www.cnblogs.com/wenbronk/p/6673117.html
Copyright © 2011-2022 走看看