Config Server存储加密内容

一 准备好一个配置文件encryption.yml
spring:
  datasource:
    username: dbuser
    password: '{cipher}851a6effab6619f43157a714061f4602be0131b73b56b0451a7e268c880daea3'
注意spring.datasource.password上的单引号不能少。但如果使用properties格式管理配置,则不需要使用单引号,否则该值不会被解密。
此时正确的写法如下:
spring.datasource.username=dbuser
spring.datasource.password={cipher}851a6effab6619f43157a714061f4602be0131b73b56b0451a7e268c880daea3
二 启动微服务microservice-config-server-encryption
三 测试
1 输入 http://localhost:8080/encryption-default.yml
2 输出结果如下:
profile: default
spring:
  datasource:
    password: mysecret
    username: dbuser
test: '1'
说明Config Server能自动解密配置内容。
四 说明
一些场景下,想要让Config Server直接返回密文本身,而非解密后的内容,可设置spring.cloud.server.encypt.enabled=false,这时可由Config Client自行解密。

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/80872324