It is a simple springboot project. only has a few properties and a MainClass:
@Slf4j
@SpringBootApplication
public class DemoApplication {
@Value("${test}")
String test;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@PostConstruct
public void print() {
log.info(test);
}
}
It just print the value of variable test.
I configure test in application.properties:
test=test normal
spring.profiles.active=dev
The variable was overrided by application-dev.properties:
test=test in dev
Then I run the application, It works. It print: test in dev
The next thing is problem:
I package the application as a jar, and I want to override the test when I run this application, So I write a file out.properties:
test=test in out
Start the application by command
java -jar target/demo.jar --spring.config.additional-location=out.properties
It still prints test in dev!
I change the command to:
java -jar target/demo.jar --test="test in command"
It print test in command.
I have read the document: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config. But I didn't find some useful tip.
My purpose is replace some property in application with a out config, so I don't have to change the source code and repackage.
Thanks for help!