springboot启动
# ApplicationRunner
package com.wujie.springboot.study.runner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(2)
@Slf4j
@Component
public class BootApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
// 开机启动
log.info("this is BootApplicationRunner...");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# CommandLineRunner
package com.wujie.springboot.study.runner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(1)
@Slf4j
@Component
public class BootCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
log.info("this is BootCommandLineRunner...");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
应用启动顺序
如果没有加上@Order
注解来进行排序,默认是ApplicationRunner
会先执行
编辑 (opens new window)
上次更新: 2022/01/06, 23:59:54