mavennoclassdeffounderrorspring-boot-jpa

Facing 'NoClassDefFoundError: org/springframework/data/repository/config/BootstrapMode' issue while running the tests


These are the spring related jars added in my pom.xml file

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>2.0.5.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>2.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.2.0.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Error that I'm seeing is :

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.185 sec <<< FAILURE! - in com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests
emptyInputShouldReturnEmptyJson(com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests)  Time elapsed: 1.145 sec  <<< ERROR!
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Users/a-5594/dev/github/eps-jobs-air-offline-cancel-sync/target/classes/com/expedia/www/eps/jobs/air/offline/cancel/sync/dataaccess/WebNotifyManager.class]; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/config/BootstrapMode
	at com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests.emptyInputShouldReturnEmptyJson(LambdaTests.java:40)
Caused by: java.lang.NoClassDefFoundError: org/springframework/data/repository/config/BootstrapMode
	at com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests.emptyInputShouldReturnEmptyJson(LambdaTests.java:40)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.config.BootstrapMode
	at com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests.emptyInputShouldReturnEmptyJson(LambdaTests.java:40)

sentenceShouldReturnFlatJsonWithWordsAndCounts(com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests)  Time elapsed: 0.033 sec  <<< ERROR!
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Users/a-5594/dev/github/eps-jobs-air-offline-cancel-sync/target/classes/com/expedia/www/eps/jobs/air/offline/cancel/sync/dataaccess/WebNotifyManager.class]; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/config/BootstrapMode
	at com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests.sentenceShouldReturnFlatJsonWithWordsAndCounts(LambdaTests.java:49)
Caused by: java.lang.NoClassDefFoundError: org/springframework/data/repository/config/BootstrapMode
	at com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests.sentenceShouldReturnFlatJsonWithWordsAndCounts(LambdaTests.java:49)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.config.BootstrapMode
	at com.expedia.www.eps.jobs.air.offline.cancel.sync.LambdaTests.sentenceShouldReturnFlatJsonWithWordsAndCounts(LambdaTests.java:49)

I tried by changing different versions of spring/jpa, etc.. in pom.xml but issue is still there.


Solution

  • Your version of spring-data-commons is too old, and that version doesn't have the BootstrapMode class. Please try upgrading it to 2.2.0.RELEASE as you have for the other spring dependencies.

    It's probably a good idea to define a version property in your pom:

    <properties>
        <spring.version>2.2.0.RELEASE</spring.version>
    </properties>
    

    And then, in your dependencies use it like this:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>${spring.version}</version>
    </dependency>
    

    Next time you want to upgrade spring, you can do it in just one place.