简体   繁体   English

如何在我的Spring Boot应用程序中从AWS访问环境变量

[英]How to access Environment Variable from AWS in my spring boot application

I am working on application which is deployed on AWS. 我正在研究部署在AWS上的应用程序。 I have set database configuration ( URL , UserName , Password ) in AWS Environment properties. 我已经在AWS Environment属性中设置了数据库配置( URLUserNamePassword )。

AWS环境变量

Now how can I access these variables in my spring boot application? 现在如何在Spring Boot应用程序中访问这些变量?

My application.properties file looks like: 我的application.properties文件如下所示:

spring.datasource.driver-class-name = <DRIVER>
spring.datasource.url = <URL>
spring.datasource.username = <USERNAME>
spring.datasource.password = <PASSWORD>

Note: Currently I am accessing database details from application.properties file 注意:当前,我正在从application.properties文件访问数据库详细信息

To use environment variables in spring boot application.properties you can use the usual Spring placeholder notation: 要在spring boot application.properties中使用环境变量,可以使用通常的Spring占位符表示法:

spring.datasource.url = ${JDBC_CONNECTION:default_value_connection}

Further explanation: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-placeholders-in-properties 进一步说明: https : //docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-placeholders-in-properties

You can set JDBC_CONNECTION value in AWS Elastic beanstalk. 您可以在AWS Elastic beantalk中设置JDBC_CONNECTION值。 If JDBC_CONNECTION environment variable not set it will use the 'default_value_connection' . 如果未设置JDBC_CONNECTION环境变量,它将使用'default_value_connection'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM