如何在我的Spring Boot应用程序中从AWS访问环境变量 [英] How to access Environment Variable from AWS in my spring boot application

查看:175
本文介绍了如何在我的Spring Boot应用程序中从AWS访问环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发在AWS上部署的应用程序.我已经在AWS Environment属性中设置了数据库配置(URLUserNamePassword).

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}

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

您可以在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆