【问题标题】:Spring properties: spring.config.additional-location not verriden property valuesSpring 属性:spring.config.additional-location 未验证属性值
【发布时间】:2019-12-23 10:21:53
【问题描述】:

我正在使用这个命令行来在本地启动我的服务:

mvn -pl rep-digital-api clean compile spring-boot:run \
  -Dspring-boot.run.arguments=--spring.config.additional-location=front-pre-props.properties

pre 配置文件已激活,因为 front-pre-props.properties 包含 spring.profiles.active=pre

进入默认application-dev.properties我已经设置了这个属性:

api.path-web=web

不过,我需要将pre 配置文件模拟到我的本地环境中。所以我需要改变这个属性值:

 api.path-web=other-path

不过,此属性并未被覆盖。

我还测试了将-Dapi.path-web=other-value 设置为 mvn 命令,但它不起作用...

有什么想法吗?

【问题讨论】:

  • 您的文件 front-pre-props.properties 位于何处?如果在classpath下,也就是在resources下,那么就不需要定义spring.config.additional-location。默认情况下,spring-boot 会选择这些位置:DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";
  • 它在我的项目之外的文件系统中。
  • 在您的情况下,您需要将位置指定为:file:./absolutepath/front-pre-props.properties
  • 您能提供更多帮助代码吗?我的意思是,我该如何指定这个值?
  • 请查看我的回答

标签: spring spring-boot spring-properties


【解决方案1】:

如果您尝试从文件系统添加文件,则需要将属性spring.config.additional-location 的值设置为file:/pathtofile/yourfile.properties

假设您的文件 front-pre-props.properties 在路径 /Users/demo/front-pre-props.properties

然后你可以执行运行命令为:

mvn -pl rep-digital-api -Dspring.config.additional-location=“file:/Users/demo/front-pre-props.properties” clean compile
spring-boot:run

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2011-01-31
    • 2012-09-18
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    相关资源
    最近更新 更多