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

2024-01-19

我正在开发部署在 AWS 上的应用程序。我已经设置了数据库配置(URL, UserName, Password) 在 AWS 环境属性中。

现在我如何在我的 Spring Boot 应用程序中访问这些变量?

My application.properties文件看起来像:

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

注意:目前我正在访问数据库详细信息application.properties file


要在 spring boot application.properties 中使用环境变量,您可以使用常用的 Spring 占位符表示法:

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 https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-placeholders-in-properties

您可以在 AWS Elastic beanstalk 中设置 JDBC_CONNECTION 值。如果未设置 JDBC_CONNECTION 环境变量,它将使用'default_value_connection'.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐