Skip to content

Commit 8bc1baf

Browse files
committed
add CommandLineRunner
1 parent d0c5367 commit 8bc1baf

File tree

8 files changed

+104
-2
lines changed

8 files changed

+104
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Spring Boot 使用的各种示例,以最简单、最实用为标准
1616
- [spring-boot-hello](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-hello):Spring Boot 2.0 Hello World 示例
1717
- [spring-boot-banner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):Spring Boot 定制 Banner 示例
1818
- [spring-boot-docker](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):使用 Docker 部署 Spring Boot 示例
19-
- [dockercompose-springboot-mysql-nginx](https://github.com/ityouknow/spring-boot-examples/tree/master/dockercompose-springboot-mysql-nginx) :Docker Compose + Spring Boot + Nginx + Mysql 示例
19+
- [dockercompose-springboot-mysql-nginx](https://github.com/ityouknow/spring-boot-examples/tree/master/dockercompose-springboot-mysql-nginx) :Docker Compose + Spring Boot + Nginx + Mysql 示例
20+
- [spring-boot-commandLineRunner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-commandLineRunner) :Spring Boot 使用 commandLineRunner 实现项目启动时资源初始化示例
21+
2022

2123
**参考文章**
2224

README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Spring Boot Examples, Use the simplest and most useful scene demo.
1616
- [spring-boot-banner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):Spring Boot Customized Banner
1717
- [spring-boot-docker](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-banner):Spring Boot with Docker
1818
- [dockercompose-springboot-mysql-nginx](https://github.com/ityouknow/spring-boot-examples/tree/master/dockercompose-springboot-mysql-nginx) :Docker Compose + Spring Boot + Nginx + Mysql example
19-
19+
- [spring-boot-commandLineRunner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-commandLineRunner) :Example of resource initialization at project startup using Spring Boot and commandLineRunner
2020

2121
---
2222

spring-boot-commandLineRunner/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>spring-boot-commandLineRunner</artifactId>
8+
<version>2.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Spring Boot banner</name>
12+
<description>Spring Boot and commandLineRunner demo</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.0.RELEASE</version>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-maven-plugin</artifactId>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
42+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.neo;
2+
3+
import org.springframework.boot.CommandLineRunner;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@SpringBootApplication
8+
public class CommandLineRunnerApplication {
9+
10+
public static void main(String[] args) {
11+
System.out.println("The service to start.");
12+
SpringApplication.run(CommandLineRunnerApplication.class, args);
13+
System.out.println("The service has started.");
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.neo.runner;
2+
3+
import org.springframework.boot.CommandLineRunner;
4+
import org.springframework.core.annotation.Order;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
@Order(1)
9+
public class OrderRunner1 implements CommandLineRunner {
10+
11+
@Override
12+
public void run(String... args) throws Exception {
13+
System.out.println("The OrderRunner1 start to initialize ...");
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.neo.runner;
2+
3+
import org.springframework.boot.CommandLineRunner;
4+
import org.springframework.core.annotation.Order;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
@Order(2)
9+
public class OrderRunner2 implements CommandLineRunner {
10+
11+
@Override
12+
public void run(String... args) throws Exception {
13+
System.out.println("The OrderRunner2 start to initialize ...");
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.neo.runner;
2+
3+
import org.springframework.boot.CommandLineRunner;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class Runner implements CommandLineRunner {
8+
9+
@Override
10+
public void run(String... args) throws Exception {
11+
System.out.println("The Runner start to initialize ...");
12+
}
13+
}

spring-boot-commandLineRunner/src/main/resources/application.properties

Whitespace-only changes.

0 commit comments

Comments
 (0)