From 738e12eee1bd9adc970131648eaa5665e402e1d9 Mon Sep 17 00:00:00 2001 From: ityouknow Date: Wed, 28 Dec 2022 16:46:28 +0800 Subject: [PATCH] add spring-boot-commandLineRunner --- README.md | 2 +- spring-boot-commandLineRunner/pom.xml | 42 +++++++++++++++++++ .../com/neo/CommandLineRunnerApplication.java | 15 +++++++ .../java/com/neo/runner/OrderRunner1.java | 15 +++++++ .../java/com/neo/runner/OrderRunner2.java | 15 +++++++ .../src/main/java/com/neo/runner/Runner.java | 13 ++++++ .../src/main/resources/application.properties | 0 7 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 spring-boot-commandLineRunner/pom.xml create mode 100644 spring-boot-commandLineRunner/src/main/java/com/neo/CommandLineRunnerApplication.java create mode 100644 spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner1.java create mode 100644 spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner2.java create mode 100644 spring-boot-commandLineRunner/src/main/java/com/neo/runner/Runner.java create mode 100644 spring-boot-commandLineRunner/src/main/resources/application.properties diff --git a/README.md b/README.md index 5767909b5..1c79dc455 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Spring Boot 使用的各种示例,以最简单、最实用为标准,此开 - [spring-boot-web-thymeleaf](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-web-thymeleaf):Spring Boot 3.0 thymeleaf 增删该查示例 - [spring-boot-jpa-thymeleaf-curd](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-jpa-thymeleaf-curd):Spring Boot 3.0 Jpa thymeleaf 列表、增删改查使用案例 - [spring-boot-file-upload](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-file-upload):Spring Boot 3.0 上传文件使用案例 - +- [spring-boot-commandLineRunner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-commandLineRunner):Spring Boot 3.0 上传文件使用案例 diff --git a/spring-boot-commandLineRunner/pom.xml b/spring-boot-commandLineRunner/pom.xml new file mode 100644 index 000000000..651f81439 --- /dev/null +++ b/spring-boot-commandLineRunner/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + com.example + spring-boot-commandLineRunner + 2.0.0 + jar + + Spring Boot banner + Spring Boot and commandLineRunner demo + + + org.springframework.boot + spring-boot-starter-parent + 3.0.0 + + + + UTF-8 + UTF-8 + 17 + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-commandLineRunner/src/main/java/com/neo/CommandLineRunnerApplication.java b/spring-boot-commandLineRunner/src/main/java/com/neo/CommandLineRunnerApplication.java new file mode 100644 index 000000000..d1f685efa --- /dev/null +++ b/spring-boot-commandLineRunner/src/main/java/com/neo/CommandLineRunnerApplication.java @@ -0,0 +1,15 @@ +package com.neo; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CommandLineRunnerApplication { + + public static void main(String[] args) { + System.out.println("The service to start."); + SpringApplication.run(CommandLineRunnerApplication.class, args); + System.out.println("The service has started."); + } +} diff --git a/spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner1.java b/spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner1.java new file mode 100644 index 000000000..ea92d0d13 --- /dev/null +++ b/spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner1.java @@ -0,0 +1,15 @@ +package com.neo.runner; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +@Order(1) +public class OrderRunner1 implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + System.out.println("The OrderRunner1 start to initialize ..."); + } +} \ No newline at end of file diff --git a/spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner2.java b/spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner2.java new file mode 100644 index 000000000..7265d82b1 --- /dev/null +++ b/spring-boot-commandLineRunner/src/main/java/com/neo/runner/OrderRunner2.java @@ -0,0 +1,15 @@ +package com.neo.runner; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +@Order(2) +public class OrderRunner2 implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + System.out.println("The OrderRunner2 start to initialize ..."); + } +} \ No newline at end of file diff --git a/spring-boot-commandLineRunner/src/main/java/com/neo/runner/Runner.java b/spring-boot-commandLineRunner/src/main/java/com/neo/runner/Runner.java new file mode 100644 index 000000000..647605d8e --- /dev/null +++ b/spring-boot-commandLineRunner/src/main/java/com/neo/runner/Runner.java @@ -0,0 +1,13 @@ +package com.neo.runner; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +public class Runner implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + System.out.println("The Runner start to initialize ..."); + } +} \ No newline at end of file diff --git a/spring-boot-commandLineRunner/src/main/resources/application.properties b/spring-boot-commandLineRunner/src/main/resources/application.properties new file mode 100644 index 000000000..e69de29bb