当我试图为我的Java项目创建安全的生产环境时,我应该将数据库用户名、密码和url保存在哪里,为了安全起见,我现在正在使用应用程序属性来保存DB凭据,请建议一些良好和安全的方法来保存DB凭据。
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项目,我应该放在哪里?
发布于 2019-05-27 08:41:16
在使用Spring时,可以在应用程序启动时传递数据库连接参数。
例如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。
https://stackoverflow.com/questions/56322167
复制相似问题