美文网首页
Springboot的 CommandLineRunner 接

Springboot的 CommandLineRunner 接

作者: 骑蚂蚁上高速_jun | 来源:发表于2020-08-08 22:08 被阅读0次

CommandLineRunner 接口的主要在框架启动后初始化执行一次的代码段。[实现的run方法只会在启动的时候执行一次]

package cn.waimaolang.wangjun.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 
 */
@Component
public class InitCommand implements CommandLineRunner
{

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void run(String... args) throws Exception {
        logger.info("框架初始化加载执行的代码"+InitCommand .class);
    }
}

CommandLineRunner 接口 & ApplicationRunner 接口 实现相同的接口

如果定义了必须按特定顺序调用的多个CommandLineRunner或ApplicationRunner beans,则可以另外实现org.springframework.core.Ordered接口或使用org.springframework.core.annotation.Order注释。

相关文章

网友评论

      本文标题:Springboot的 CommandLineRunner 接

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