Closed bhavya475 closed 7 months ago
This sounds similar to ClassNotFoundException: jakarta.json.spi.JsonProvider
that other users have encountered.
Can you use the instructions provided at in https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html#class-not-found-jsonprovider and report if this resolves the issue?
Hi,
I'm having the same issue with version 8.8.2 of the client. Adding the dependency does not solve it.
It is tied to using Spring Boot starter version 2.7 as parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
If I switch to version 3.1.1 I don't reproduce the issue...
And it's a real pain in the neck since I need this 2.7 version due to Azure dependencies that don't handle Spring 3...
@bhavya475 are you usgin Spring 2.7 also per chance?
I actually found a workaround, by chance I stumbled upon this StackOverflow post: https://stackoverflow.com/questions/68040881/jaxb-moxy-unmarshalling-json-runs-into-error-exception-in-thread-main-java-lan
Adding the dependency:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
solves the issue, no more ClassNotFoundException
on startup.
Hi,
I'm facing similar issue Method threw 'java.lang.NoClassDefFoundError' exception
and, even after adding the dependencies suggested by @ngsoftwaredev, the issue still persists.
pom.xml spring boot starter version
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.6.6</version>
<relativePath/>
</parent>
pom.xml dependencies specific to ES
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.13.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.json</artifactId>
<version>2.0.1</version>
</dependency>
Any help is appreciated. Thanks.
Hi, @PriyanshMaheshwari
The issue you're facing seems to be caused by the fact that spring-boot-dependencies-2.6.6.pom sets <jakarta-json.version>1.1.6</jakarta-json.version>
, which overrides the version you specified (2.0.1).
To resolve this, you can override the jakarta-json.version
property in your pom.xml
to ensure the correct version is used. Add the following section to your pom.xml
under the <properties>
tag:
<properties>
<jakarta-json.version>2.0.1</jakarta-json.version>
</properties>
This should force Spring Boot to use the correct version of jakarta.json
. Let me know if this helps!
Thanks.
Java API client version
8.1.3
Java version
1.8
Elasticsearch Version
8.1.3
Problem description
Getting this error java.lang.ClassNotFoundException: jakarta.json.JsonException tags changed: → language-clients Failed to instantiate [co.elastic.clients.Elasticsearch.ElasticsearchClient]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: jakarta/json/JsonException
@bean public ElasticsearchClient client() throws Exception { RestClient restClient = RestClient.builder( new HttpHost(esHost, esPort)).build();
// Create the transport with a Jackson mapper ElasticsearchTransport transport = new RestClientTransport( restClient, new JacksonJsonpMapper());
// And create the API client return new ElasticsearchClient(transport); } Dependency: