@PropertySource("文件:$ {env.variable.name} /file.properties")在Windows上不起作用

时间:2018-02-24 12:07:20

标签: spring spring-boot properties environment-variables properties-file

我正在开发一个具有外部化测试配置的spring-boot应用程序。我使用@PropertySource注释读取配置文件,如下所示 - @PropertySource("file:path-to-file-on-file-system/file.properties")

如果路径是硬编码的,它可以在Windows和Linux系统上运行,但为了使其可配置,我创建了一个环境变量,用于存储文件系统上文件的绝对路径。

  1. 在Linux上export PROPS=/usr/local/config

  2. 在Windows上System > Advanced System Settings > Advanced > Environment Variables > New System Variable > Name=PROPS & Value=C:/Users/Dev/Config

  3. 然后@PropertySource("file:${PROPS}/file.properties")

    这在Linux上无缝运行,但在Windows系统上抛出异常,如下所示

      

    无法解决占位符' PROPS'在字符串值中   "文件:$ {PROPS} /file.properties"

    echo %PROPS%在命令行上显示正确的路径。

    非常感谢您解决此问题的任何帮助。

0 个答案:

没有答案