繁体   English   中英

使用spring.config.location命令行arg时,为Spring的@PropertySource设置什么?

[英]What to set for Spring's @PropertySource when using spring.config.location command line arg?

我已经定义了一个@Config类,如下所示:

@Config
@PropertySource(value = "")
public class Foo {
...
}

我通过运行以下程序来运行程序:

 --spring.config.location=file:///Users/dev/workspace/application.yml

问题是我无法省略PropertySource批注的'value'属性。 为什么需要设置? 那会覆盖我在--spring.config.location设置的--spring.config.location吗? 我应该使用SimpleCommandLinePropertySource而不是--spring.config.location吗?

当您使用spring.config.location使用外部属性文件时,只需在配置类中设置值:

@Config
@PropertySource(value = "${spring.config.location}")
public class Foo {
...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM