一、在(第 031 篇)講解了如何連接對稱加密的配置服務端,而連接對稱非對稱加密的配置微服務也是一樣的; 二、配置客戶端不須要作什麼加解密的配置,加解密的配置在服務端作就行了; 三、這裏還順便列舉下配置路徑的規則: /**************************************************************************************** * 配置服務的路勁規則: * * /{application}/{profile}[/{label}] * /{application}-{profile}.yml * /{label}/{application}-{profile}.yml * /{application}-{profile}.properties * /{label}/{application}-{profile}.properties ****************************************************************************************/
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>springms-config-client-encrypt-rsa</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>com.springms.cloud</groupId> <artifactId>springms-spring-cloud</artifactId> <version>1.0-SNAPSHOT</version> </parent> <dependencies> <!-- 客戶端配置模塊 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- web模塊 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
server: port: 8270
##################################################################################################### # 配置服務客戶端Client應用入口(連接 ClientServer 測試) spring: cloud: config: uri: http://localhost:8265 # 連接 springms-config-client-encrypt-rsa 微服務 profile: stg1rsa # 選擇 stg1rsa 配置文件 label: master #當 ConfigServer 的後端存儲的是 Git 的時候,默認就是 master application: name: foobar #取 foobar-stg1rsa.yml 這個文件的 application 名字,即爲 foobar 名稱 #####################################################################################################
package com.springms.cloud.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * 配置客戶端Controller。 * * @author hmilyylimh * * @version 0.0.1 * * @date 17/10/18 * */ @RestController public class ConfigClientEncryptRsaController { @Value("${profile}") private String profile; @GetMapping("/profile") public String getProfile(){ return this.profile; } }
package com.springms.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * 配置客戶端ConfigClient連接通過RSA加解密的配置微服務。 * * 配置服務客戶端Client應用入口(連接通過 RSA 非對稱加解密的配置微服務)(專門爲測試通過 RSA 非加解密的配置微服務 springms-config-server-encrypt-rsa 微服務模塊)。<br/> * * @author hmilyylimh * * @version 0.0.1 * * @date 17/10/18 * */ @SpringBootApplication public class MsConfigClientEncryptRsaApplication { public static void main(String[] args) { SpringApplication.run(MsConfigClientEncryptRsaApplication.class, args); System.out.println("【【【【【【 ConfigClientEncryptRsa微服務 】】】】】】已啓動."); } }
/**************************************************************************************** 1、配置服務客戶端Client應用入口(連接通過 RSA 非加解密的配置微服務)(專門爲測試通過 RSA 非加解密的配置微服務 springms-config-server-encrypt-rsa 微服務模塊): 一、註解:pom.xml 先添加 configclient 的引用模; 二、編輯 bootstrap.yml 文件,注意註釋 profile 屬性,而後添加相關客戶端配置; spring: cloud: config: uri: http://localhost:8265 # 連接 springms-config-client-encrypt-rsa 微服務 profile: stg1rsa # 選擇stg1rsa配置文件 label: master #當 ConfigServer 的後端存儲的是 Git 的時候,默認就是 master application: name: foobar #取 foobar-dev.yml 這個文件的 application 名字,即爲 foobar 名稱 三、啓動 springms-config-server-encrypt-rsa 模塊服務,啓動1個端口; 四、啓動 springms-config-client-encrypt-rsa 模塊服務,啓動1個端口; 五、在瀏覽器輸入地址 http://localhost:8270/profile 正常狀況下會輸出配置文件的內容(內容爲:foobar-stg2rsa); 總結:正常打印,說明配置服務客戶端不須要作什麼加解密的配置,加解密的配置在服務端作就行了; ****************************************************************************************/
https://gitee.com/ylimhhmily/SpringCloudTutorial.gitjava
SpringCloudTutorial交流QQ羣: 235322432git
SpringCloudTutorial交流微信羣: 微信溝通羣二維碼圖片連接web
歡迎關注,您的確定是對我最大的支持!!!spring