-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
From StackOverflow:
Considering a Spring Boot
CommandLineRunner
Application, I would like to know how to filter the "switch" options passed to Spring Boot as externalized configuration.For example, with:
@Component public class FileProcessingCommandLine implements CommandLineRunner { @Override public void run(String... strings) throws Exception { for (String filename: strings) { File file = new File(filename); service.doSomething(file); } } }
I can call
java -jar myJar.jar /tmp/file1 /tmp/file2
and the service will be called for both files.But if I add a Spring parameter, like
java -jar myJar.jar /tmp/file1 /tmp/file2 --spring.config.name=myproject
then the configuration name is updated (right!) but the service is also called for file./--spring.config.name=myproject
which of course doesn't exist.I know I can filter manually on the filename with something like
if (!filename.startsWith("--")) ...
But as all of this components came from Spring, I wonder if there is not a option somewhere to let it manage it, and to ensure the
strings
parameter passed to therun
method will not contain at all the properties options already parsed at the Application level.