spring_reference/IV. Spring Boot features/22.6. Using the CommandLine...

16 lines
703 B
Markdown
Raw Normal View History

### 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注解。