java.lang.ClassCastException:ConditionalOnJava $ JavaVersion无法转换为org.springframework.boot.system.JavaVersion

问题描述 投票:4回答:4

我的项目在另一台PC上正常运行。但是我使用import existing maven项目在另一台PC上导入了它。

在新的PC设置中,我有以下设置:

Project -> properties -> java compiler version -> set to 1.8

Project -> project facets -> java version ->  set to 1.8

它显示JRE System Library [javaSE-1.8]

pom.xml有<java-version>1.8</java-version>和maven插件:

<plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.6.1</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>
    </plugins>

如果我运行clean install以上设置,则以下是控制台错误:

2018-05-18 10:07:56.255  INFO 5644 --- [           main] com.dvl.AssetTrackerApplication          : Starting AssetTrackerApplication on DESKTOP-M0588P2 with PID 5644 (started by Dhaval in E:\STS Workspace\AssetTracker)
2018-05-18 10:07:56.255  INFO 5644 --- [           main] com.dvl.AssetTrackerApplication          : No active profile set, falling back to default profiles: default
2018-05-18 10:07:56.317  INFO 5644 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2cc44ad: startup date [Fri May 18 10:07:56 IST 2018]; root of context hierarchy
2018-05-18 10:07:57.380  WARN 5644 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.dvl.AssetTrackerApplication]; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration$LegacyMetricRepositoryConfiguration
2018-05-18 10:07:57.396  INFO 5644 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-18 10:07:57.396  INFO 5644 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-05-18 10:07:57.412 ERROR 5644 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.dvl.AssetTrackerApplication]; 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:645) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.lambda$processDeferredImportSelectors$2(ConfigurationClassParser.java:564) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1378) ~[na:na]
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:560) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at com.dvl.AssetTrackerApplication.main(AssetTrackerApplication.java:27) [classes/:na]
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:64) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:221) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:359) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:265) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:635) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    ... 17 common frames omitted
Caused by: java.lang.ClassCastException: org.springframework.boot.autoconfigure.condition.ConditionalOnJava$JavaVersion cannot be cast to org.springframework.boot.system.JavaVersion
    at org.springframework.boot.autoconfigure.condition.OnJavaCondition.getMatchOutcome(OnJavaCondition.java:48) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
    ... 23 common frames omitted

然后我试着在一些SO答案中建议使用spring-boot-maven-plugin

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> 

与此我删除/评论maven-compiler-plugin

即使我有以下情况,这也会自动更改JRE System Library [javaSE-1.6](1.8到1.6):

Project -> properties -> java compiler version -> set to 1.8
Project -> project facets -> java version ->  set to 1.8 
pom.xml has <java-version>1.8</java-version> 

并在“问题”窗口中给出以下错误:Java compiler level does not match the version of the installed

所以我尝试在所有地方更改版本1.6解决了版本不匹配问题,但当我运行clean install然后再次在控制台中给出相同的(上面)堆栈跟踪。

编辑:mvn dependency:tree的输出:

[INFO] com.dvl:assetTracker:jar:1.0
[INFO] +- org.springframework:spring-webmvc:jar:4.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.3.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.3.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.4.2.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.4.2.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.2.RELEASE:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.6:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.8.4:compile
[INFO] |     +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.4:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.8.4:compile
[INFO] +- org.postgresql:postgresql:jar:9.4.1212.jre7:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.4.2.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.4.2.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.2.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:2.5.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO] |  |  \- org.json:json:jar:20140107:test
[INFO] |  \- org.springframework:spring-test:jar:4.3.4.RELEASE:test
[INFO] +- org.springframework:spring-orm:jar:4.3.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-jdbc:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.3.4.RELEASE:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- org.apache.tomcat.embed:tomcat-embed-jasper:jar:8.5.6:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.6:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.6:compile
[INFO] |  \- org.eclipse.jdt.core.compiler:ecj:jar:4.5.1:compile
[INFO] +- jboss:javassist:jar:3.4.ga:compile
[INFO] +- c3p0:c3p0:jar:0.9.1:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- com.itextpdf:itextpdf:jar:5.0.6:compile
[INFO] |  +- org.bouncycastle:bcmail-jdk14:jar:1.38:compile
[INFO] |  +- org.bouncycastle:bcprov-jdk14:jar:1.38:compile
[INFO] |  \- org.bouncycastle:bctsp-jdk14:jar:1.38:compile
[INFO] +- org.apache.poi:poi:jar:3.14:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:3.14:compile
[INFO] |  +- org.apache.poi:poi-ooxml-schemas:jar:3.14:compile
[INFO] |  |  \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] |  |     \- stax:stax-api:jar:1.0.1:compile
[INFO] |  \- com.github.virtuald:curvesapi:jar:1.03:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.0.11.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-ehcache:jar:5.0.11.Final:compile
[INFO] |  \- net.sf.ehcache:ehcache-core:jar:2.4.3:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.0.11.Final:compile
[INFO] +- org.hibernate:hibernate-envers:jar:5.0.11.Final:compile
[INFO] +- org.hibernate:hibernate-java8:jar:5.0.11.Final:compile
[INFO] +- org.hibernate:hibernate-jpamodelgen:jar:5.0.11.Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.3.3:compile
[INFO] +- org.hibernate:hibernate-validator-annotation-processor:jar:5.2.4.Final:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.4.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.4.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.2.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.6.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.6.2:compile
[INFO] \- org.apache.logging.log4j:log4j-jcl:jar:2.5:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:20 min
[INFO] Finished at: 2018-05-18T11:36:54+05:30
[INFO] Final Memory: 21M/66M
[INFO] ------------------------------------------------------------------------

欢迎所有评论。谢谢。

java maven spring-boot spring-tool-suite
4个回答
1
投票

springboot升级后我遇到了同样的错误。 spring-boot-actuator-autoconfigure包含类conditionalOnJava,用于反向兼容java。不知何故,这个版本类在升级后在我的情况下失败了。在我的情况下,它在clean build / clean install后没有刷新,所以我删除了gradle / maven缓存。

gradle用户:

  • 删除〜/ .gradle的内容
  • gradle clean build

对于eclipse用户来说:

  • 在eclipse中刷新gradle项目(如果你使用buildship插件)
  • 通过删除遗留依赖项来清理java构建路径(项目 - >属性 - > java构建路径 - >库)

maven用户:

  • 删除〜/ .m2的内容
  • 干净安装

0
投票

您的问题是由版本引起的:spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE.Maybe您的本地存储库是版本2.0.1,但您的项目正在使用其他版本。如果是我说obove,您可以删除本地存储库的2.0.1版本并尝试再次运行该项目。


0
投票

如果上述情况不起作用,请检查您是否有任何依赖项的重复引用。在我的例子中,project-A依赖于project-B并在pom文件中指定。最重要的是,在buildpath-> projects上有另一个对project-B的显式引用。

删除构建路径引用解决了ConditionalOnJava $ JavaVersion无法转换为org.springframework.boot.system.JavaVersion的问题


-1
投票

我的解决方案是...使用IntelliJ:p

© www.soinside.com 2019 - 2024. All rights reserved.