本人出现问题场景:
springboot-parent的版本为2.2.6,elasticsearch的版本为7.8.0。
出现问题的时候是在执行SpringTest的JUnit单元测试的时候出现的,然后还去Run As的Maven test后也出现相同的问题。但是在正常Run As的Java application时完全没有问题,所以问题出现在Junit的时候。
Cause By:java.lang.ClassNotFoundException:org.elasticsearch.action.Action
然后查了好多资料也没弄清,主要是正常启动整个项目不出错,只在Junit出现问题,所以检查下Maven的问题。
Maven的pom.xml部分如下:
<!-- ES -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.8.0</version>
<exclusions>
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.8.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.8.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.8.0</version>
<exclusions>
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>7.8.0</version>
</dependency>
<!-- ES -->
解决办法:
很简单...因为使用的elasticsearch的版本太高了,所以把springboot的parent更新到2.3.1就好了如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<!-- <relativePath /> -->
</parent>