简体   繁体   中英

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

I have defined a @Config class like so:

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

I run my program by including the following:

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

The problem is that I cannot omit the 'value' attribute of the PropertySource annotation. Why do you need to set that? Will that overwrite what I have set in --spring.config.location ? Should I use SimpleCommandLinePropertySource instead of --spring.config.location ?

When you use external property file using spring.config.location you just have to set for value in your configuration class:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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