其他分享
首页 > 其他分享> > SpringBoot自启动方式

SpringBoot自启动方式

作者:互联网

SpringBoot自启动方式

SprinngBoot 有两种启动方式:

1、ApplicationRunner

默认情况

ApplicationRunner 优先级高于CommandLineRunner 

可以通过@Order注解来调整优先级

package com.caicai.springboot.study.Runner;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/*
 *添加的一个Bean注,因为需要被Spring 扫描到
 * 默认情况 ApplicationRunner 执行优先级高于CommandRunner
 * */
//@Order(1) //调试执行优先级,数值越小,执行优先级越高
@Component // bean注解
@Slf4j
public class SpringBootApplicationRunner implements ApplicationRunner {


    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("This is ApplicationRunner ");
    }
}

  

2、CommandLineRunner 

package com.caicai.springboot.study.Runner;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/*
* 添加Bean注解
* */
//@Order(1) //调试执行优先级,数值越小,执行优先级越高
@Component
@Slf4j
public class SpringBootCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
log.info("This is CommandLineRunner ");
}
}

 

参:

 

标签:CommandLineRunner,优先级,SpringBoot,方式,springframework,org,自启动,import,ApplicationRu
来源: https://www.cnblogs.com/caicai920/p/14352946.html