java.lang.ClassCastException: ConditionalOnJava $ JavaVersion нельзя преобразовать в org.springframework.boot.system.JavaVersion. - PullRequest
0 голосов
/ 18 мая 2018

Мой проект работал нормально на другом ПК.но я импортировал его на другой ПК, используя импорт существующего проекта maven.

В новой настройке ПК у меня есть следующие настройки:

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

Затем я попыталсяиспользовать spring-boot-maven-plugin, как предлагается в некоторых ответах SO:

<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] ------------------------------------------------------------------------

Все комментарии приветствуются.Спасибо.

Ответы [ 4 ]

0 голосов
/ 22 июня 2019

Мое решение было ... использовать IntelliJ: p

0 голосов
/ 17 октября 2018

Ваша проблема вызвана версией: spring-boot-autoconfigure-2.0.1.RELEASE.jar: 2.0.1.RELEASE。 Возможно, ваш локальный репозиторий является версией 2.0.1 ,, но ваш проект использует другую версию。 Еслиэто то, что я сказал выше, вы можете удалить версию 2.0.1 вашего локального репозитория и попробовать запустить проект снова.

0 голосов
/ 18 апреля 2019

На всякий случай, если не сработало вышеперечисленное, проверьте, есть ли у вас дублирующая ссылка на какую-либо зависимость.В моем случае project-A зависит от project-B и указывается в файле pom.Кроме того, в buildpath-> projects была еще одна явная ссылка на project-B.

Удаление ссылки на buildpath решило проблему, когда ConditionalOnJava $ JavaVersion не может быть приведен к org.springframework.boot.system.JavaVersion.

0 голосов
/ 25 мая 2018

У меня была такая же ошибка после обновления при загрузке.spring-boot-actuator-autoconfigure содержит класс conditionalOnJava, который предназначен для обратной совместимости Java.Каким-то образом это приведение к классу версии не удалось в моем случае после обновления.В моем случае он не обновлялся после clean build / clean install, поэтому я удалил кеш gradle / maven.

gradle users:

  • удалить содержимое ~ / .gradle
  • gradle clean build

дополнительно для пользователей затмения:

  • обновить проект gradle в eclipse (на случай, если выиспользуйте плагин сборки)
  • очистите путь сборки Java, удалив устаревшие зависимости (проект-> свойства -> путь сборки Java -> библиотеки)

maven пользователи:

  • удалить содержимое ~ / .m2
  • чистой установки
...