我定义了一个 @Config
类,如下所示:
@Config
@PropertySource(value = "")
public class Foo {
...
}
我通过包含以下内容来运行我的程序:
--spring.config.location=file:///Users/dev/workspace/application.yml
问题是我无法省略 PropertySource 注释的“value”属性。为什么需要这样设置?这会覆盖我在 --spring.config.location
中设置的内容吗?我应该使用 SimpleCommandLinePropertySource
而不是 --spring.config.location
吗?
最佳答案
当您使用 spring.config.location 来使用外部属性文件时,您只需在配置类中设置值:
@Config
@PropertySource(value = "${spring.config.location}")
public class Foo {
...
}
关于java - 使用 spring.config.location 命令行参数时,为 Spring 的 @PropertySource 设置什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44358392/