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
- Installation | Elasticsearch Java API Client [8.13] | Elastic
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.