Spring boot CommandLineRunner invokes all classes with run method

I have multiple classes which uses CommandLineRunner for running the application. But when i start the application using spring-boot-maven-plugin all the classes are invoked one after another. This happens even if I run the class as main method. How can I overcome this. Any help will be greatly appreciated.

Using the below code in pom to identify the main method

<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.2.4.RELEASE</version> <configuration> <mainClass>com.Foo</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>


A potential solution for you, that I used to get around a similar problem. Similar, but not exact same, so I can't guarentee success.

You can try using @ConditionalOnExpression on each implementation, with different values. Like so: @ConditionalOnExpression("'${some.property}'=='myValue'").

Add the property in application.properties to set a default implementation, and when running the jar you can override that implementation with java -jar myApp.jar --some.property=myOtherValue.

Spring boot should select the correct implementation to use, based on which implementation matches the value of the property you set.

Need Your Help

How do I disable the opening and closing animation of the DropDown of a ComboBox in WPF?

wpf animation combobox drop-down-menu

When I put a combobox in my WPF app, at runtime, when I click it, it rolls down the included items. After selection, it rolls the DropDown up again.

In Apps Script, How to include optional arguments in custom functions

javascript google-apps-script google-sheets custom-function

I want to write a custom function which has some mandatory arguments but can also accept a few optional arguments. I couldn't find any documentation on this. Does anyone know? Is it similar to Java...