Given the Spring Boot CommandLineRunner
, I would like to know how to filter out the "switch" options passed to Spring Boot as an external configuration.
For example, using
@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, for example java -jar myJar.jar /tmp/file1 /tmp/file2 --spring.config.name=myproject
, then the configuration name will be updated (correctly!), But the service is also called for the file ./--spring.config.name=myproject
, which of course does not exist.
I know that I can manually filter by file name with something like
if (!filename.startsWith("--")) ...
But since all these components came from Spring, I wonder if there is an option somewhere that allows it to be controlled, and to ensure that the strings
parameter passed to the run
method does not contain any property parameters already analyzed at the application level.
source share