# NoClassDefFoundError exception with SpringBoot in Elasticsearch7.3

**URL:** <https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385>\
**Category:** Elasticsearch\
**Created:** [November 11, 2019, 4:18pm UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385 "2019-11-11T16:18:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardooooo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ricardooooo/32/57548_2.png) [@Ricardooooo](https://discuss.elastic.co/u/Ricardooooo)\
**Post date:** [November 11, 2019, 4:18pm UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385/1 "2019-11-11T16:18:07Z")

</div>

Hi!  
I try to create document via high level rest client with:

```auto
Map<String, Object> jsonMap = new HashMap<>();
jsonMap.put("name", "Bob");
jsonMap.put("id", "123456");
IndexRequest indexRequest = new IndexRequest("lead").id("123456").source(jsonMap);
client.index(indexRequest, RequestOptions.DEFAULT);

```

But it throws a NoClassDefFoundError: org/apache/lucene/util/BytesRefIterator.  
The elastic version is 7.3.2.

That's the elasticsearch dependency in my pom.

```auto
            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>7.3.2</version>
            </dependency>
            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>elasticsearch-rest-high-level-client</artifactId>
                <version>7.3.2</version>
            </dependency>

```

```auto
The full stacktrace:
Exception in thread "Thread-20" java.lang.NoClassDefFoundError: org/apache/lucene/util/BytesRefIterator
	at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:397)
	at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:377)
	at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:365)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.createDocument(MetadataDocumentBuilderImpl.java:182)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.build(MetadataDocumentBuilderImpl.java:76)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.getPage(MetadataDocumentBuilderImpl.java:163)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.getSyncMetadata(MetadataDocumentBuilderImpl.java:121)
	at com.sunyard.mdhome.thread.MetadataSyncThread.run(MetadataSyncThread.java:30)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.BytesRefIterator
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 9 more

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 11, 2019, 5:42pm UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385/2 "2019-11-11T17:42:58Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

When using springboot with  
elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your `pom.xml`:

```auto
<properties>
  <elasticsearch.version>7.3.0<elasticsearch.version>
</properties>

```

See documentation here: [https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions)

---

<div class="post-metadata">

**Author:** ![Ricardooooo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ricardooooo/32/57548_2.png) [@Ricardooooo](https://discuss.elastic.co/u/Ricardooooo)\
**Post date:** [November 12, 2019, 1:47am UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385/3 "2019-11-12T01:47:11Z")

</div>

Hi, I've already declared the elasticsearch version 7.3.2 in the pom.xml. But the error still exists.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 12, 2019, 6:03am UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385/4 "2019-11-12T06:03:28Z")

</div>

Could you run

```
mvn dependency:tree
```

---

<div class="post-metadata">

**Author:** ![Ricardooooo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ricardooooo/32/57548_2.png) [@Ricardooooo](https://discuss.elastic.co/u/Ricardooooo)\
**Post date:** [November 12, 2019, 2:28pm UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385/5 "2019-11-12T14:28:23Z")

</div>

Hi, I've formatted my code in markdown syle. So it'll be easier to be read.

According to your advice, I've found out the cause of the error. There's another dependence in this project which includes a 3.5.0 version of `lucene-core.jar`. It conflicts with the 8.1.0 version `lucene-core.jar` in elasticsearch. The program uses the 3.5.0 version actually while the program is running.

Although I haven't worked out how to fix the version confilict by not influencing the formmer module, the cause of the error is clear now. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 10, 2019, 2:28pm UTC](https://discuss.elastic.co/t/noclassdeffounderror-exception-with-springboot-in-elasticsearch7-3/207385/6 "2019-12-10T14:28:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
