【问题标题】:How to save DB username and password Spring boot project [duplicate]如何保存数据库用户名和密码Spring boot项目[重复]
【发布时间】:2019-10-12 19:11:00
【问题描述】:

我应该将数据库用户名、密码和 url 保存在哪里,以确保在我尝试为我的 Java 项目创建安全的生产环境时保持安全, 目前我正在使用应用程序属性来保存数据库凭据,请建议一些好的和安全的方法来保存数据库凭据。

application.properties

# This should be used only for credentials and other local-only config.
spring.datasource.url = jdbc:postgresql://localhost/database
spring.datasource.username = root
spring.datasource.password = root@123

我应该将安全和生产 Spring boot 项目保存在哪里

【问题讨论】:

    标签: java spring spring-boot security application.properties


    【解决方案1】:

    由于您使用的是 Spring Boot,您可以在应用程序启动时传递数据库连接参数。

    例如java -jar your-spring-boot-app.jar -Dspring.datasource.url=jdbc:postgresql://localhost/database ...

    您也可以将它们设置为系统环境变量:

    export SPRING_DATASOURCE_URL="jdbc:postgresql://localhost/database" 然后像往常一样启动您的应用程序。

    这样,您只需将连接参数存储在您实际使用它们的服务器上,并防止意外将它们检入您的代码版本控制系统。

    https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

    为了提高安全性,您可以使用https://projects.spring.io/spring-vault/ 或外部配置服务器https://spring.io/projects/spring-cloud-config

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多