Java Can';t使用不同Spring启动版本的库

Java Can';t使用不同Spring启动版本的库,java,spring,spring-boot,gradle,Java,Spring,Spring Boot,Gradle,我有一个旧的主项目,其中我使用Spring Boot版本1.3.5.0。在这个项目中,我想使用我编写的库。该库使用SpringBootVersion2.2.5.0版本 我使用Gradle作为构建工具。该项目构建得很好,但当我尝试运行它时,会得到以下错误输出: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration cl

我有一个旧的主项目,其中我使用Spring Boot版本1.3.5.0。在这个项目中,我想使用我编写的库。该库使用SpringBootVersion2.2.5.0版本

我使用Gradle作为构建工具。该项目构建得很好,但当我尝试运行它时,会得到以下错误输出:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [hr.kapsch.npgw.NpgwReferenceDatabaseApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration$LegacyMetricRepositoryConfiguration
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:609)
    at org.springframework.context.annotation.ConfigurationClassParser.access$800(ConfigurationClassParser.java:110)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:811)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at hr.kapsch.npgw.NpgwReferenceDatabaseApplication.main(NpgwReferenceDatabaseApplication.java:10)
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration$LegacyMetricRepositoryConfiguration
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
    at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:225)
    at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:371)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:271)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:599)
    ... 19 common frames omitted
Caused by: java.lang.IllegalStateException: Attribute 'value' in annotation org.springframework.boot.autoconfigure.condition.ConditionalOnJava should be compatible with org.springframework.boot.system.JavaVersion but a org.springframework.boot.autoconfigure.condition.ConditionalOnJava$JavaVersion value was returned
    at org.springframework.core.annotation.TypeMappedAnnotation.adaptForAttribute(TypeMappedAnnotation.java:536)
    at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:461)
    at org.springframework.core.annotation.TypeMappedAnnotation.getValue(TypeMappedAnnotation.java:401)
    at org.springframework.core.annotation.TypeMappedAnnotation.asMap(TypeMappedAnnotation.java:286)
    at org.springframework.core.annotation.AbstractMergedAnnotation.asAnnotationAttributes(AbstractMergedAnnotation.java:193)
    at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:106)
    at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:81)
    at org.springframework.boot.autoconfigure.condition.OnJavaCondition.getMatchOutcome(OnJavaCondition.java:43)
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
    ... 25 common frames omitted

我试图寻找解决办法。我没有在任何地方找到完全相同的异常,但从我发现的情况来看,我怀疑问题在于主项目和库中的Spring引导版本不兼容。我试图搜索关于不同Spring启动版本兼容性的信息,但没有找到任何有用的信息。

混合Spring版本不是一个好主意,因为它可能导致意外行为。 因为较新版本的spring有新的类等,而使用较低版本将导致NoSuchMethodError或ClassNotFoundException

它还可能在运行时导致一些不可预测的异常。
为了避免这种行为,请使用一致且兼容的spring boot版本。

与此同时,我发现了。释放的第一个数字表示主要释放。不同的主要版本不向后兼容(在我的例子1和2中)。因此,为了在旧项目中使用新库,我必须将新库中的Spring引导版本更改为主版本1的任何版本