From 1a1280bf2df06f522b29bf71a115075b9aff6bc5 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Mon, 3 Aug 2020 15:33:50 +0800 Subject: [PATCH] Springboot configuration order --- .gitignore | 1 + application.yml | 4 + config/application.yml | 4 + core/application.yml | 4 + core/config/application.yml | 4 + core/core.iml | 96 +++++++++++++++++++ core/pom.xml | 26 +++++ .../core/SpringWebApplication.java | 26 +++++ .../core/config/SystemConfiguration.java | 11 +++ .../core/config/SystemProperties.java | 23 +++++ core/src/main/resources/application.yml | 5 + .../src/main/resources/config/application.yml | 5 + demo-parent.iml | 2 - pom.xml | 3 +- 14 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 application.yml create mode 100644 config/application.yml create mode 100644 core/application.yml create mode 100644 core/config/application.yml create mode 100644 core/core.iml create mode 100644 core/pom.xml create mode 100644 core/src/main/java/com/duanledexianxianxian/core/SpringWebApplication.java create mode 100644 core/src/main/java/com/duanledexianxianxian/core/config/SystemConfiguration.java create mode 100644 core/src/main/java/com/duanledexianxianxian/core/config/SystemProperties.java create mode 100644 core/src/main/resources/application.yml create mode 100644 core/src/main/resources/config/application.yml diff --git a/.gitignore b/.gitignore index ac4a37d..8d56944 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,4 @@ buildNumber.properties .idea !/demo-parent.iml !/demo-parent.iml +!/.idea/ diff --git a/application.yml b/application.yml new file mode 100644 index 0000000..2b583ea --- /dev/null +++ b/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 +#system: +# name: "root" diff --git a/config/application.yml b/config/application.yml new file mode 100644 index 0000000..56ec753 --- /dev/null +++ b/config/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 +#system: +# name: "root config" diff --git a/core/application.yml b/core/application.yml new file mode 100644 index 0000000..0c4af99 --- /dev/null +++ b/core/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 +system: + name: "core" diff --git a/core/config/application.yml b/core/config/application.yml new file mode 100644 index 0000000..cf3688f --- /dev/null +++ b/core/config/application.yml @@ -0,0 +1,4 @@ +server: + port: 8080 +system: + name: "core config" diff --git a/core/core.iml b/core/core.iml new file mode 100644 index 0000000..d681e71 --- /dev/null +++ b/core/core.iml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/pom.xml b/core/pom.xml new file mode 100644 index 0000000..8175d84 --- /dev/null +++ b/core/pom.xml @@ -0,0 +1,26 @@ + + + + demo-parent + com.duanledexianxianxian.demo + 1.0-SNAPSHOT + + 4.0.0 + + core + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + \ No newline at end of file diff --git a/core/src/main/java/com/duanledexianxianxian/core/SpringWebApplication.java b/core/src/main/java/com/duanledexianxianxian/core/SpringWebApplication.java new file mode 100644 index 0000000..382f67e --- /dev/null +++ b/core/src/main/java/com/duanledexianxianxian/core/SpringWebApplication.java @@ -0,0 +1,26 @@ +package com.duanledexianxianxian.core; + + +import com.duanledexianxianxian.core.config.SystemProperties; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +/** + * springboot 应用程序入口 + * @author duanledexianxianxian + */ +@SpringBootApplication +public class SpringWebApplication { + + public static void main(String[] args) { + ApplicationContext applicationContext= (ApplicationContext) SpringApplication.run(SpringWebApplication.class, args); + SystemProperties properties=applicationContext.getBean(SystemProperties.class); + System.out.println("用户的当前工作目录:"+System.getProperty("user.dir")); + // 打印出配置参数 + System.out.println(properties.getName()); + + } + + +} diff --git a/core/src/main/java/com/duanledexianxianxian/core/config/SystemConfiguration.java b/core/src/main/java/com/duanledexianxianxian/core/config/SystemConfiguration.java new file mode 100644 index 0000000..600c458 --- /dev/null +++ b/core/src/main/java/com/duanledexianxianxian/core/config/SystemConfiguration.java @@ -0,0 +1,11 @@ +package com.duanledexianxianxian.core.config; + +import org.springframework.context.annotation.Configuration; + +/** + * 配置类 + * @author duanledexianxian + */ +@Configuration +public class SystemConfiguration { +} diff --git a/core/src/main/java/com/duanledexianxianxian/core/config/SystemProperties.java b/core/src/main/java/com/duanledexianxianxian/core/config/SystemProperties.java new file mode 100644 index 0000000..2026bc2 --- /dev/null +++ b/core/src/main/java/com/duanledexianxianxian/core/config/SystemProperties.java @@ -0,0 +1,23 @@ +package com.duanledexianxianxian.core.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 系统配置类 + * @author duanledexianxianxian + */ +@Component +@ConfigurationProperties(prefix = "system") +@Data +public class SystemProperties { + /** + * 名称 + */ + private String name; + /** + * 编码 + */ + private String code; +} diff --git a/core/src/main/resources/application.yml b/core/src/main/resources/application.yml new file mode 100644 index 0000000..4956d98 --- /dev/null +++ b/core/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + port: 8080 + +system: + name: "classpath root config" \ No newline at end of file diff --git a/core/src/main/resources/config/application.yml b/core/src/main/resources/config/application.yml new file mode 100644 index 0000000..85845d7 --- /dev/null +++ b/core/src/main/resources/config/application.yml @@ -0,0 +1,5 @@ +server: + port: 8080 + +#system: +# name: "classpath config" \ No newline at end of file diff --git a/demo-parent.iml b/demo-parent.iml index 28baa0d..2384313 100644 --- a/demo-parent.iml +++ b/demo-parent.iml @@ -59,8 +59,6 @@ - - diff --git a/pom.xml b/pom.xml index 06796d7..f9ecdfe 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,7 @@ pom 1.0-SNAPSHOT - kafka - menu + core -- GitLab