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/