首页 > 解决方案 > Spring Boot 2 没有获取操作系统环境变量

问题描述

我已经设置了一些操作系统变量,并希望 Spring 自动选择它们。

在此处输入图像描述

但这不会发生。例如,spring.datasource.username应该从 OS 变量中提取,尽管我在运行应用程序时收到此错误java.sql.SQLSyntaxErrorException: Access denied for user ''@'localhost'

两者都没有spring.profiles.active被拾起,因此我看到了这个No active profile set, falling back to default profiles: default

标签: javaspringspring-bootenvironment-variablesapplication.properties

解决方案


这些环境变量看起来不太正确。我认为 Spring 会期望它们像

SPRING_PROFILES_ACTIVE
SPRING_APPLICATION_JSON

作为实际的环境变量。我已经能够设置其他值,但它们需要采用该格式作为环境变量。

更多细节可以在

https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/htmlsingle/#boot-features-external-config


推荐阅读