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

**URL:** <https://discuss.elastic.co/t/receiving-nested-exception-java-lang-noclassdeffounderror-jakarta-json-jsonexception-when-trying-to-use-elasticsearchclient-with-springboot-in-java/360742>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 3, 2024, 6:04pm UTC](https://discuss.elastic.co/t/receiving-nested-exception-java-lang-noclassdeffounderror-jakarta-json-jsonexception-when-trying-to-use-elasticsearchclient-with-springboot-in-java/360742 "2024-06-03T18:04:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priyansh\_Maheshwari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priyansh_maheshwari/32/135010_2.png) [@Priyansh\_Maheshwari](https://discuss.elastic.co/u/Priyansh_Maheshwari)\
**Post date:** [June 3, 2024, 6:04pm UTC](https://discuss.elastic.co/t/receiving-nested-exception-java-lang-noclassdeffounderror-jakarta-json-jsonexception-when-trying-to-use-elasticsearchclient-with-springboot-in-java/360742/1 "2024-06-03T18:04:16Z")

</div>

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

- [Getting this error java.lang.ClassNotFoundException: jakarta.json.JsonException · Issue #311 · elastic/elasticsearch-java · GitHub](https://github.com/elastic/elasticsearch-java/issues/311)
- [Installation | Elasticsearch Java API Client [8.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html#class-not-found-jsonprovider)

Spring version: 3.1.1

Providing the pom.xml file (Dependencies):-

```auto
    <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:-

```auto
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:-

```auto
    @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.

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [June 4, 2024, 8:28am UTC](https://discuss.elastic.co/t/receiving-nested-exception-java-lang-noclassdeffounderror-jakarta-json-jsonexception-when-trying-to-use-elasticsearchclient-with-springboot-in-java/360742/2 "2024-06-04T08:28:17Z")

</div>

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](https://github.com/elastic/elasticsearch-java) provides a full working [example](https://github.com/elastic/elasticsearch-java/tree/main/examples/realworld-app) using Spring boot which can be used as reference. Hope this helps!
