5

My project was running fine in another PC. but I imported it in another PC using import existing maven project.

In new PC setup I have below settings:

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

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

it shows JRE System Library [javaSE-1.8]

pom.xml has <java-version>1.8</java-version> and below maven plugin :

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

With above settings if I run clean install then below are the console errors:

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

Then I tried to use spring-boot-maven-plugin as suggested in some SO answers:

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

with this I removed/commented maven-compiler-plugin

This changed JRE System Library [javaSE-1.6] (1.8 to 1.6) automatically even if I had :

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> 

and gives below error : Java compiler level does not match the version of the installed in "Problems" window.

so I tried changing versions at all places to 1.6 which solved version mismatch problem but when I ran clean install then again gave same (above) stacktrace in console.

EDIT: output of 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] ------------------------------------------------------------------------

All comments are welcome. Thank You.

R Dhaval
  • 536
  • 1
  • 9
  • 21
  • What's the output of `mvn dependency:tree`? – tgdavies May 18 '18 at 05:38
  • @tgdavies added in the edit. – R Dhaval May 18 '18 at 06:11
  • And which version of the `spring-boot-maven-plugin` are you using. The stack dump mentions spring boot 2.0.1 while your pom seems to specify 1.4.2 – tgdavies May 18 '18 at 06:48
  • I haven't mentioned any version in there. Looks like it is taking latest release by default. and yeah my project is a bit old so it had older version 1.4.2. I will change `spring-boot-maven-plugin` to 1.4.2 and will try installing. Thanks for the suggestions. I'll come back with results soon. – R Dhaval May 18 '18 at 07:27
  • @tgdavies if I add `version 1.4.2` to `spring-boot-maven-plugin` then a warning `Duplicating managed version 1.4.2.RELEASE for spring-boot-maven-plugin` is shown. Anyway I did `clean install` after this and got exactly same stack dump as above. – R Dhaval May 19 '18 at 05:38
  • I have solved this by deleting `.m2 repository` and my project from sts. Then I imported the old project again and ran the `clean install`. But now I have another problem- After I hit the app URL in the browser I get this exceptionin: `org.apache.jasper.JasperException: The absolute uri: http://www.springframework.org/tags/form cannot be resolved in either web.xml or the jar files deployed with this application`. I found a few solutions on SO and other sites but till now they haven't work for me. – R Dhaval May 19 '18 at 09:35
  • This Answer : https://stackoverflow.com/a/27276690/5204909 solved my `org.apache.jasper.JasperException: The absolute uri: http://www.springframework.org/tags/form cannot be resolved in either web.xml or the jar files deployed with this application` problem. – R Dhaval May 19 '18 at 10:22

4 Answers4

2

I had the same error after a springboot upgrade. spring-boot-actuator-autoconfigure contains the class conditionalOnJava which is for reverse compatibility of java. Somehow this version class casting failed in my case after the upgrade. In my case it didn't get refreshed after a clean build/ clean install so I removed the gradle/maven cache.

gradle users:

  • delete the content of ~/.gradle
  • gradle clean build

additional for eclipse users:

  • refresh gradle project in eclipse (in case you use the buildship plugin)
  • clean the java build path by removing legacy dependencies (project-> properties -> java build path -> libraries)

maven users :

  • delete the content of ~/.m2
  • clean install
SWiggels
  • 2,159
  • 1
  • 21
  • 35
  • 1
    I get this as a run time error. I am not sure how would deleting gradle/maven content would help? – Andy Dufresne Dec 18 '18 at 10:02
  • This solution shows what you can do after importing a project from a machine where it ran successfully. It just cleans out m2 from eventual outdated depenencies. – SWiggels Dec 19 '18 at 12:16
0

Your problem is caused by version:spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE。Maybe your local repository is the version 2.0.1,but your project is using other version。 If it is what I said obove,you can delete your local repository's version 2.0.1 and try to run the project again.

0

Just in case if non of the above worked, check if you have duplicate reference of any dependency. In my case, project-A has a dependency on project-B and is specified in the pom file. On top of it, there was another explicit reference to project-B on buildpath->projects.

Removing the buildpath reference resolved the issue of ConditionalOnJava$JavaVersion cant be cast to org.springframework.boot.system.JavaVersion

Madhu Stv
  • 89
  • 2
  • 8
0

In my case

By me was added dependency whose include older version of Spring Boot, for exmple - promethues.io dependepncy include old version spring-boot.

For resolve it:

  1. Exclude older version:
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_spring_boot</artifactId>
            <version>${io.prometheus.version}</version>
            <exclusions>
                <exclusion>  <!-- declare the exclusion here -->
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
                <exclusion>  <!-- declare the exclusion here -->
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-test</artifactId>
                </exclusion>
                <exclusion>  <!-- declare the exclusion here -->
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-actuator</artifactId>
                </exclusion>
                <exclusion>  <!-- declare the exclusion here -->
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-aop</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
  1. And ADD your version:
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${org.springframework-boot-version}</version>
        </dependency>
...etc
Dmitry
  • 1