有没有办法在 Spring Boot 应用程序配置中使用 Spring Cloud {cipher}? [英] Is there a way to use Spring Cloud {cipher} in Spring Boot application config?

查看:30
本文介绍了有没有办法在 Spring Boot 应用程序配置中使用 Spring Cloud {cipher}?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Spring Cloud Config 的 Spring Boot 应用程序,但我想加密 Spring Boot 应用程序 bootstrap.yml 文件中的 Spring Cloud Config 密码.有没有办法做到这一点?下面是一个例子.

I have a Spring Boot app that is using Spring Cloud Config but I would like to encrypt the Spring Cloud Config password in the Spring Boot apps bootstrap.yml file. Is there a way to do this? Below is an example.

Spring Boot 应用程序 bootstrap.yml

Spring Boot app bootstrap.yml

spring:
  cloud:
    config:
      uri: http://locahost:8888
      username: user
      password: '{cipher}encryptedpassword'

推荐答案

我发现了一些与此相关的事情.

A couple things I've discovered related to this.

如果使用bootstrap.yml(或application.yml),密文格式必须用单引号括起来:

If you use bootstrap.yml (or application.yml), the format for the cipher text must enclosed within single quotes:

security.user.password: '{cipher}56e611ce4a99ffd99908d2c9aa1461d831722812e4370a5b6900b7ea680ae914'  

如果你使用bootstrap.properties(或application.properties),密文的格式一定不能包含:

If you use bootstrap.properties (or application.properties), the format for the cipher text must NOT be enclosed:

security.user.password= {cipher}56e611ce4a99ffd99908d2c9aa1461d831722812e4370a5b6900b7ea680ae914

[reference docs][1] 显示没有引号的 yml,我从来没有使用过.SnakeYaml 老是报错:

The [reference docs][1] show the yml without the quotes, which I never got to work. SnakeYaml always reported an error:

"expected <block end>, but found Scalar"

这篇关于有没有办法在 Spring Boot 应用程序配置中使用 Spring Cloud {cipher}?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆