如何在我的Spring Boot应用程序中从AWS访问环境变量 [英] How to access Environment Variable from AWS in my spring boot application
问题描述
我正在开发在AWS上部署的应用程序.我已经在AWS Environment属性中设置了数据库配置(URL
,UserName
,Password
).
I am working on application which is deployed on AWS. I have set database configuration (URL
, UserName
, Password
) in AWS Environment properties.
现在如何在Spring Boot应用程序中访问这些变量?
Now how can I access these variables in my spring boot application?
我的application.properties
文件如下:
spring.datasource.driver-class-name = <DRIVER>
spring.datasource.url = <URL>
spring.datasource.username = <USERNAME>
spring.datasource.password = <PASSWORD>
注意:当前,我正在从application.properties
文件访问数据库详细信息
Note: Currently I am accessing database details from application.properties
file
推荐答案
要在Spring Boot application.properties中使用环境变量,可以使用通常的Spring占位符:
To use environment variables in spring boot application.properties you can use the usual Spring placeholder notation:
spring.datasource.url = ${JDBC_CONNECTION:default_value_connection}
您可以在AWS Elastic beantalk中设置JDBC_CONNECTION值.如果未设置JDBC_CONNECTION环境变量,它将使用'default_value_connection'
.
You can set JDBC_CONNECTION value in AWS Elastic beanstalk. If JDBC_CONNECTION environment variable not set it will use the 'default_value_connection'
.
这篇关于如何在我的Spring Boot应用程序中从AWS访问环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!