Home > Back-end >  Upgrading from springboot version 2.3.8.RELEASE to 2.4.0 and getting these errors for junit tests
Upgrading from springboot version 2.3.8.RELEASE to 2.4.0 and getting these errors for junit tests

Time:03-09

I am new to springboot and trying to upgrade from 2.3.8.RELEASE to 2.4.0 and my test cases are failing. I am getting these error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration$HikariDataSourceMetricsConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/LatencyUtils/PauseDetector

Caused by: java.lang.NoClassDefFoundError: org/LatencyUtils/PauseDetector

Caused by: java.lang.ClassNotFoundException: org.LatencyUtils.PauseDetector
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)

I tried googling them but solutions there didn't help me. Can you please let me know what could be it's root cause and how to resolve them?

Edit: my build.gradle is here:

dependencies {
        // spring
        compileOnly "org.springframework.boot:spring-boot-starter-web"
        compileOnly "org.springframework.boot:spring-boot-starter-actuator"
        compileOnly "org.springframework.boot:spring-boot-starter-data-jpa"
        compileOnly "org.springframework.boot:spring-boot-starter-thymeleaf"
        compileOnly "org.springframework.security.oauth"  
                ".boot:spring-security-oauth2-autoconfigure:$springSecurityOauth2Autoconfigure"
        compileOnly "org.springframework.security.oauth:spring-security-oauth:$springSecurityOauth"
        compileOnly "org.springframework.retry:spring-retry"

        
        compileOnly "org.hibernate:hibernate-core:5.4.24.Final"


        compileOnly "org.modelmapper:modelmapper:$modelmapperVersion"
        compileOnly "org.cache2k:cache2k-core:$cache2kVersion"
        compileOnly "com.fasterxml.jackson.core:jackson-databind:$jacksonDatabindVersion"
        compileOnly "com.fasterxml.jackson.core:jackson-core:$jacksonDatabindVersion"
        compileOnly "com.fasterxml.jackson.core:jackson-annotations:$jacksonDatabindVersion"
        compileOnly "org.flywaydb:flyway-core:5.2.4"
        
        compileOnly "org.projectlombok:lombok"
        annotationProcessor "org.projectlombok:lombok"

        implementation group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.6.4'

        compileOnly "org.springframework.boot:spring-boot-starter-freemarker"


        testImplementation "org.junit.jupiter:junit-jupiter:5.5.1"
        testImplementation "org.springframework.security:spring-security-test"
        testImplementation "org.springframework.restdocs:spring-restdocs-mockmvc"
        testImplementation("org.springframework.cloud:spring-cloud-stream-test-support") {
            exclude group: "junit", module: "junit"
        }
        testImplementation "com.h2database:h2"
        testImplementation "org.mockito:mockito-junit-jupiter"
        testAnnotationProcessor "org.projectlombok:lombok"
    }

CodePudding user response:

I also face the same issue while migrating from springboot 2.3.8.RELEASE to 2.4.13 and I fixed it using

implementation "org.springframework.boot:spring-boot-starter-actuator"

instead of

compileOnly "org.springframework.boot:spring-boot-starter-actuator"

Explaination: If you don't need module in run-time use "compileOnly" to reduce memory usage but the module is required at runtime then we use "implementation".

  • Related