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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With