java - 环境变量中的数据库凭据?

标签 java database spring spring-boot

Stackoverflow 和其他网站上的许多开发人员建议将数据库密码存储在环境变量中。我们正在使用 Spring Boot,我们想知道即使在生产环境中,它是否真的是一种避免在 application.properties 文件中使用明文密码的好方法(安全且常见)?如果不是,什么是更好的解决方案?

请注意,我们需要为 DEV 和 PROD 使用不同的 .properties 文件。

最佳答案

我建议你看看 Spring Cloud Config :

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments.

特点:

Spring Cloud Config Server features:

  • HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)
  • Encrypt and decrypt property values (symmetric or asymmetric)
  • Embeddable easily in a Spring Boot application using @EnableConfigServer

Config Client features (for Spring applications):

  • Bind to the Config Server and initialize Spring Environment with remote property sources
  • Encrypt and decrypt property values (symmetric or asymmetric)

您可以找到配置服务器的工作示例 here

关于java - 环境变量中的数据库凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53314933/

相关文章:

php - MySQL 数据透视行在 sql fiddle 中运行,但在语法模型 codeigniter 中不起作用

Spring Boot 仍然需要 web.xml 中的资源引用

java - 如何启用 Hibernate 查询计时以进行日志记录

java - Android:索引 0 无效,大小为 0。在哪里?

java套接字编程: message delivery order

java - Android 中的 SimpleDateFormat 在 Android 1.6 中提供不需要的时区

database - 将DateTime对象上传到NoSQL数据库时出错

c# - 会计数据库模式

java - 将您的 Session 转换为 FlushMode.COMMIT/AUTO 或从事务定义中删除 'readOnly' 标记

java - ThreadLocalRandom 如何减少争用?