spring - 从application.properties文件中读取环境变量 [英] spring - read environment variables from inside the application.properties file
本文介绍了spring - 从application.properties文件中读取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 application.properties 文件中指定了Spring属性。如何从环境变量中填充这些属性?
I specified Spring properties inside the application.properties file. How can i populate those properties from the environment variables?
这是我尝试过的,但它似乎不起作用:
Here is what I tried, but it doesn't seem to work:
application.properties
spring.datasource.url=jdbc:postgresql://#{ systemProperties['DATABASE_HOST']}:5432/dbname
spring.datasource.username = postgres
spring.datasource.password = postgres
推荐答案
您可以像使用 $ {引用Spring属性一样引用环境属性...}
语法。
在您的情况下:
spring.datasource.url=jdbc:postgresql://${DATABASE_HOST}:5432/dbname
这篇关于spring - 从application.properties文件中读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文