From 54b0c4b51ff36ba990bb36e2a39fde0ca5eeb815 Mon Sep 17 00:00:00 2001
From: YunaiV <>
Date: Mon, 20 Jan 2020 19:19:51 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E7=A4=BA=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lab-43/lab-43-demo-configname/pom.xml | 23 +++++++++
.../lab43/propertydemo/Application.java | 48 +++++++++++++++++++
.../src/main/resources/application.yaml | 1 +
.../src/main/resources/rpc.yaml | 1 +
.../target/classes/application.yaml | 1 +
lab-43/lab-43-demo-jasypt/pom.xml | 37 ++++++++++++++
.../lab43/propertydemo/Application.java | 13 +++++
.../src/main/resources/application.yaml | 11 +++++
.../lab43/propertydemo/JasyptTest.java | 35 ++++++++++++++
lab-43/pom.xml | 2 +
10 files changed, 172 insertions(+)
create mode 100644 lab-43/lab-43-demo-configname/pom.xml
create mode 100644 lab-43/lab-43-demo-configname/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java
create mode 100644 lab-43/lab-43-demo-configname/src/main/resources/application.yaml
create mode 100644 lab-43/lab-43-demo-configname/src/main/resources/rpc.yaml
create mode 100644 lab-43/lab-43-demo-configname/target/classes/application.yaml
create mode 100644 lab-43/lab-43-demo-jasypt/pom.xml
create mode 100644 lab-43/lab-43-demo-jasypt/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java
create mode 100644 lab-43/lab-43-demo-jasypt/src/main/resources/application.yaml
create mode 100644 lab-43/lab-43-demo-jasypt/src/test/java/cn/iocoder/springboot/lab43/propertydemo/JasyptTest.java
diff --git a/lab-43/lab-43-demo-configname/pom.xml b/lab-43/lab-43-demo-configname/pom.xml
new file mode 100644
index 00000000..ed36d88a
--- /dev/null
+++ b/lab-43/lab-43-demo-configname/pom.xml
@@ -0,0 +1,23 @@
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.2.RELEASE
+
+
+ 4.0.0
+
+ lab-43-demo-configname
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+
diff --git a/lab-43/lab-43-demo-configname/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java b/lab-43/lab-43-demo-configname/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java
new file mode 100644
index 00000000..4404b91b
--- /dev/null
+++ b/lab-43/lab-43-demo-configname/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java
@@ -0,0 +1,48 @@
+package cn.iocoder.springboot.lab43.propertydemo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.config.ConfigFileApplicationListener;
+import org.springframework.stereotype.Component;
+
+@SpringBootApplication
+public class Application {
+
+ /**
+ * 设置需要读取的配置文件的名字。
+ * 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。
+ */
+ private static final String CONFIG_NAME_VALUE = "application,rpc";
+
+ public static void main(String[] args) {
+ // 设置环境变量
+ System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE);
+
+ // 启动 Spring Boot 应用
+ SpringApplication.run(Application.class, args);
+ }
+
+ @Component
+ public class ValueCommandLineRunner implements CommandLineRunner {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Value("${application-test}")
+ private String applicationTest;
+
+ @Value("${rpc-test}")
+ private String rpcTest;
+
+ @Override
+ public void run(String... args) {
+ logger.info("applicationTest:" + applicationTest);
+ logger.info("rpcTest:" + rpcTest);
+ }
+
+ }
+
+}
diff --git a/lab-43/lab-43-demo-configname/src/main/resources/application.yaml b/lab-43/lab-43-demo-configname/src/main/resources/application.yaml
new file mode 100644
index 00000000..7d82dc53
--- /dev/null
+++ b/lab-43/lab-43-demo-configname/src/main/resources/application.yaml
@@ -0,0 +1 @@
+application-test: hahaha
diff --git a/lab-43/lab-43-demo-configname/src/main/resources/rpc.yaml b/lab-43/lab-43-demo-configname/src/main/resources/rpc.yaml
new file mode 100644
index 00000000..068e7cb3
--- /dev/null
+++ b/lab-43/lab-43-demo-configname/src/main/resources/rpc.yaml
@@ -0,0 +1 @@
+rpc-test: yeah
diff --git a/lab-43/lab-43-demo-configname/target/classes/application.yaml b/lab-43/lab-43-demo-configname/target/classes/application.yaml
new file mode 100644
index 00000000..7d82dc53
--- /dev/null
+++ b/lab-43/lab-43-demo-configname/target/classes/application.yaml
@@ -0,0 +1 @@
+application-test: hahaha
diff --git a/lab-43/lab-43-demo-jasypt/pom.xml b/lab-43/lab-43-demo-jasypt/pom.xml
new file mode 100644
index 00000000..01e667cc
--- /dev/null
+++ b/lab-43/lab-43-demo-jasypt/pom.xml
@@ -0,0 +1,37 @@
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.2.RELEASE
+
+
+ 4.0.0
+
+ lab-43-demo-jasypt
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+
+ com.github.ulisesbocchio
+ jasypt-spring-boot-starter
+ 3.0.2
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
diff --git a/lab-43/lab-43-demo-jasypt/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java b/lab-43/lab-43-demo-jasypt/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java
new file mode 100644
index 00000000..01a7f359
--- /dev/null
+++ b/lab-43/lab-43-demo-jasypt/src/main/java/cn/iocoder/springboot/lab43/propertydemo/Application.java
@@ -0,0 +1,13 @@
+package cn.iocoder.springboot.lab43.propertydemo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+}
diff --git a/lab-43/lab-43-demo-jasypt/src/main/resources/application.yaml b/lab-43/lab-43-demo-jasypt/src/main/resources/application.yaml
new file mode 100644
index 00000000..960f9d97
--- /dev/null
+++ b/lab-43/lab-43-demo-jasypt/src/main/resources/application.yaml
@@ -0,0 +1,11 @@
+spring:
+ application:
+# name: ENC(xQZuD8KnkqzIGep0FFH0DYJ3Re9TrKTdvu2fxIlWNpwFcdNGhkpCag==)
+# name: ENC(KoaHnIhRGiCdWh0T2lby899Cov6MyiAXrW5PadJ3XFY=)
+ name: demo-application
+
+jasypt:
+ # jasypt 配置项,对应 JasyptEncryptorConfigurationProperties 配置类
+ encryptor:
+ algorithm: PBEWithMD5AndDES # 加密算法
+ password: ${JASYPT_PASSWORD} # 加密秘钥
diff --git a/lab-43/lab-43-demo-jasypt/src/test/java/cn/iocoder/springboot/lab43/propertydemo/JasyptTest.java b/lab-43/lab-43-demo-jasypt/src/test/java/cn/iocoder/springboot/lab43/propertydemo/JasyptTest.java
new file mode 100644
index 00000000..b1d62e8f
--- /dev/null
+++ b/lab-43/lab-43-demo-jasypt/src/test/java/cn/iocoder/springboot/lab43/propertydemo/JasyptTest.java
@@ -0,0 +1,35 @@
+package cn.iocoder.springboot.lab43.propertydemo;
+
+import org.jasypt.encryption.StringEncryptor;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class JasyptTest {
+
+ @Autowired
+ private StringEncryptor encryptor;
+
+ @Test
+ public void encode() {
+ String applicationName = "demo-application";
+ System.out.println(encryptor.encrypt(applicationName));
+ }
+
+ @Value("${spring.application.name}")
+ private String applicationName;
+
+ @Test
+ public void print() {
+ System.out.println(applicationName);
+ }
+
+ @Value("${jasypt.encryptor.password}")
+ private String password;
+
+}
diff --git a/lab-43/pom.xml b/lab-43/pom.xml
index db3dca28..45477b43 100644
--- a/lab-43/pom.xml
+++ b/lab-43/pom.xml
@@ -14,6 +14,8 @@
lab-43-demo
lab-43-demo-profiles
+ lab-43-demo-jasypt
+ lab-43-demo-configname