From 158a99881b18c1d16ac088a826a9579b5bfd075e Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Sun, 8 Feb 2015 21:44:15 +0800 Subject: [PATCH] Update 22.6. Using the CommandLineRunner.md --- .../22.6. Using the CommandLineRunner.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/IV. Spring Boot features/22.6. Using the CommandLineRunner.md b/IV. Spring Boot features/22.6. Using the CommandLineRunner.md index e69de29..5ce744c 100644 --- a/IV. Spring Boot features/22.6. Using the CommandLineRunner.md +++ b/IV. Spring Boot features/22.6. Using the CommandLineRunner.md @@ -0,0 +1,15 @@ +### 22.6. 命令行启动器 + +如果你想获取原始的命令行参数,或一旦SpringApplication启动,你需要运行一些特定的代码,你可以实现CommandLineRunner接口。在所有实现该接口的Spring beans上将调用run(String… args)方法。 +```java +import org.springframework.boot.* +import org.springframework.stereotype.* + +@Component +public class MyBean implements CommandLineRunner { + public void run(String... args) { + // Do something... + } +} +``` +如果一些CommandLineRunner beans被定义必须以特定的次序调用,你可以额外实现org.springframework.core.Ordered接口或使用org.springframework.core.annotation.Order注解。