Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d5c9acd

Browse files
[add] CommandLineRunner接口的使用
1 parent adb10d0 commit d5c9acd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package demo.web.config;
2+
3+
import org.springframework.boot.CommandLineRunner;
4+
import org.springframework.core.annotation.Order;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* parent
9+
* demo.web.config
10+
* Spring Boot的CommandLineRunner接口主要用于实现在应用初始化后,去执行一段代码块逻辑,如初始化数据等
11+
* 这段初始化代码在整个应用生命周期内只会执行一次。
12+
*
13+
* @author BlueDriver
14+
* @email cpwu@foxmail.com
15+
* @date 2019年06月05日 09:01 Wednesday
16+
* 参考:https://www.cnblogs.com/chenpi/p/9696310.html
17+
*/
18+
@Component
19+
@Order(1)//如果有多个实现CommandLineRunner的类,指定执行顺序,会从小到大一次执行
20+
public class ApplicationStartupRunner implements CommandLineRunner {
21+
@Override
22+
public void run(String... args) throws Exception {
23+
System.err.println(">>>>>>>>>>>>>>>服务启动后执行,可用户执行初始化数据等操作<<<<<<<<<<<<");
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /