Receiving nested exception "java.lang.NoClassDefFoundError: jakarta/json/JsonException" when trying to use ElasticsearchClient with SpringBoot in Java

Hi, I am new to Elasticsearch and trying to implement ElasticsearchClient in an already existing SpringBoot application. However, I am receiving the error "java.lang.NoClassDefFoundError: jakarta/json/JsonException" whenever I try to use "new JacksonJsonpMapper()" in the code.

Already tried solutions specified in the following forums/docs however, none of them helped as such:-

Spring version: 3.1.1

Providing the pom.xml file (Dependencies):-

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>8.13.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>1.5.5.Final</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20240303</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
    </dependencies>

Complete error:-

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClientConfiguration' defined in file [/codemill/maheshpr-r/event-driven-scheduler/elastic-search/target/classes/deshaw/batch/elasticsearch/client/ElasticsearchClientConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [deshaw.batch.elasticsearch.client.ElasticsearchClientConfiguration$$EnhancerBySpringCGLIB$$a6de19b7]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: jakarta/json/JsonException

Code implementation:-

    @Bean
    public ElasticsearchClient elasticsearchClient() throws URISyntaxException {
        RestClient restClient = RestClient
                .builder(new HttpHost(host, port))
                .build();

        transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
        return new ElasticsearchClient(transport);
    }

Thanks for the help.

Hello!
I tried creating a minimal sample project copying the provided pom and Bean and it works correctly. The problem could be related to older versions of spring autoconfiguration and spring data having some compatibility problems with other dependencies.
I'd suggest rebuilding the pom using only the minimal necessary dependencies just to make the Bean build correctly and then adding later what you need. The java client repository on github provides a full working example using Spring boot which can be used as reference. Hope this helps!