【发布时间】:2020-12-30 03:53:58
【问题描述】:
我正在使用 Spring Boot 3.2.1。
我不想将敏感数据作为application.yml 放在配置文件中。所以他们指的是环境变量。
在应用程序的 IntelliJ 配置设置(Environment variables 部分)中执行正常。
但是,从控制台执行 maven 失败:
./mvnw -Ddemo-api-key=all56 -Ddemo-host=https://demo.api spring-boot:run
这里是异常详情:
java.lang.IllegalArgumentException: Not enough variable values available to expand 'demo-host'
at org.springframework.web.util.UriComponents$VarArgsTemplateVariables.getValue(UriComponents.java:367) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.util.UriComponents.expandUriComponent(UriComponents.java:262) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.util.HierarchicalUriComponents$PathSegmentComponent.expand(HierarchicalUriComponents.java:960) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:434) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:52) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.util.UriComponents.expand(UriComponents.java:172) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
这是来自application.yml的sn-p:
car-parks-url: ${demo-host}/cap-ws/getCarParks?apiKey=${demo-api-key}
如果我把它放在更高的 application.yml 它工作正常:
demo-api-key: all56
demo-host: https://demo.api
URL 格式正确,所有数据都被正确提取。
无法理解使用 maven 将其作为环境变量传递时遗漏了什么?
【问题讨论】:
标签: spring-boot maven environment-variables yaml