资讯专栏INFORMATION COLUMN

SpringCloud(第 033 篇)配置客户端ConfigClient链接经过对称加解密的配置微

ARGUS / 643人阅读

SpringCloud(第 033 篇)配置客户端ConfigClient链接经过对称加解密的配置微服务

-

一、大致介绍
1、在(第 031 篇)讲解了如何链接对称加密的配置服务端,而链接对称非对称加密的配置微服务也是同样的;
2、配置客户端不需要做什么加解密的配置,加解密的配置在服务端做就好了;

3、这里还顺便列举下配置路径的规则:
/****************************************************************************************
 * 配置服务的路劲规则:
 *
 * /{application}/{profile}[/{label}]
 * /{application}-{profile}.yml
 * /{label}/{application}-{profile}.yml
 * /{application}-{profile}.properties
 * /{label}/{application}-{profile}.properties
 ****************************************************************************************/
二、实现步骤 2.1 添加 maven 引用包


    4.0.0

    springms-config-client-encrypt-rsa
    1.0-SNAPSHOT
    jar

    
        com.springms.cloud
        springms-spring-cloud
        1.0-SNAPSHOT
    

    
        
        
            org.springframework.cloud
            spring-cloud-starter-config
        

        
        
            org.springframework.boot
            spring-boot-starter-web
        
    

2.2 添加应用配置文件(springms-config-client-encrypt-rsa/src/main/resources/application.yml)
server:
  port: 8270

2.3 添加 bootstrap.yml 应用配置文件(springms-config-client-encrypt-rsa/src/main/resources/bootstrap.yml)
#####################################################################################################
# 配置服务客户端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 名称
#####################################################################################################
2.4 添加Web控制层类(springms-config-client-encrypt-rsa/src/main/java/com/springms/cloud/controller/ConfigClientEncryptRsaController.java)
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;
    }
}
2.5 添加应用启动类(springms-config-client-encrypt-rsa/src/main/java/com/springms/cloud/MsConfigClientEncryptRsaApplication.java)
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 微服务模块)。
* * @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微服务 】】】】】】已启动."); } }
三、测试
/****************************************************************************************
 一、配置服务客户端Client应用入口(链接经过 RSA 非加解密的配置微服务)(专门为测试经过 RSA 非加解密的配置微服务 springms-config-server-encrypt-rsa 微服务模块):

 1、注解:pom.xml 先添加 configclient 的引用模;
 2、编辑 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 名称
 3、启动 springms-config-server-encrypt-rsa 模块服务,启动1个端口;
 4、启动 springms-config-client-encrypt-rsa 模块服务,启动1个端口;

 5、在浏览器输入地址 http://localhost:8270/profile 正常情况下会输出配置文件的内容(内容为:foobar-stg2rsa);

 总结:正常打印,说明配置服务客户端不需要做什么加解密的配置,加解密的配置在服务端做就好了;
 ****************************************************************************************/
四、下载地址

https://gitee.com/ylimhhmily/SpringCloudTutorial.git

SpringCloudTutorial交流QQ群: 235322432

SpringCloudTutorial交流微信群: 微信沟通群二维码图片链接

欢迎关注,您的肯定是对我最大的支持!!!

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/67811.html

相关文章

  • SpringCloud 031 配置户端ConfigClient链接经过对称解密配置

    摘要:添加应用启动类配置客户端链接经过对称加解密的配置微服务专门为测试经过对称加解密的配置微服务微服务模块。 SpringCloud(第 031 篇)配置客户端ConfigClient链接经过对称加解密的配置微服务 - 一、大致介绍 1、Git服务端的文件内容进行了加密处理,那么是不是配置客户端拿到内容之后需要解密呢? 2、答案显然不是的,因为这样解密的话,先不说实现起来的难易程度,单从表面...

    DDreach 评论0 收藏0
  • SpringCloud 035 配置服务户端ConfigClient链接经过认证配置服务

    SpringCloud(第 035 篇)配置服务客户端ConfigClient链接经过认证的配置服务端 - 一、大致介绍 1、前面一章节讲解了服务端配置安全认证,那么本章节就讲解如何链接上服务端的认证; 2、这里还顺便列举下配置路径的规则: /*****************************************************************************...

    klivitamJ 评论0 收藏0
  • SpringCloud 030 配置服务端ClientServer对配置文件内容进行对称

    摘要:第篇配置服务端对配置文件内容进行对称加解密一大致介绍前面我们也简单讲解了如何搭建配置服务端微服务,也搭建了配置客户端微服务,但是呢,我们存储在上面的内容为明文,在生产环境的话,也不利于传输,特别一些重要的信息容易被泄露所以此章节,我们讲解 SpringCloud(第 030 篇)配置服务端ClientServer对配置文件内容进行对称加解密 - 一、大致介绍 1、前面我们也简单讲解了如...

    beita 评论0 收藏0
  • SpringCloud 029 配置户端 ConfigClient 接入配置服务端

    SpringCloud(第 029 篇)配置客户端 ConfigClient 接入配置服务端 - 一、大致介绍 1、有配置服务端,那么势必就会有与之对应的客户端,SpringCloud 文档中集成也非常简单; 2、但是这里有点需要注意,就是 bootstrap 配置文件,官方建议我们在bootstrap中放置不更改的属性,我们同样也需要在这里做一些简单不易于改变的配置; 3、这里还顺便列举下配置...

    YFan 评论0 收藏0
  • SpringCloud 036 )单点手动动态刷新ConfigClient配置

    摘要:添加应用启动类单点手动动态刷新配置。配置客户端服务想要实现自动刷新配置的话,一端是不要做任何处理,只需要在一端处理即可。 SpringCloud(第 036 篇)单点手动动态刷新ConfigClient配置 - 一、大致介绍 1、当ConfigServer启动后,假如我们新增配置内容的话,是不是要重新启动一下ConfigServer呢? 2、答案肯定是不需要重新启动的,因为 Sprin...

    wanglu1209 评论0 收藏0

发表评论

0条评论

ARGUS

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<