java Spring boot CommandLineRunner使用run方法调用所有类
我有多个使用CommandLineRunner运行应用程序的类。但是当我使用spring boot maven插件启动应用程序时,所有的类都会一个接一个地被调用。即使我将类作为主方法运行,也会发生这种情况。我怎样才能克服这个问题。任何帮助都将不胜感激
在pom中使用以下代码来识别主要方法
<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>
# 1 楼答案
对你来说,这是一个潜在的解决方案,我过去经常遇到类似的问题。相似,但不完全相同,所以我不能保证成功
您可以尝试在每个实现上使用@ConditionalOnExpression,使用不同的值。就像这样:
@ConditionalOnExpression("'${some.property}'=='myValue'")
在
application.properties
中添加属性以设置默认实现,在运行jar时,可以使用java -jar myApp.jar some.property=myOtherValue
覆盖该实现Spring boot应该根据哪个实现与您设置的属性值匹配,选择要使用的正确实现