springboot集成elasticsearch客户端问题记录

Easter79
• 阅读 342

1背景说明

服务端ES版本为5.5.2,springboot版本为1.5.6。

工程中添加如下依赖

springboot集成elasticsearch客户端问题记录

2问题记录

2.1 NetworkPlugin类找不到

报错java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPlugin

和java.lang.NoClassDefFoundError: org/elasticsearch/plugins/NetworkPlugin

springboot集成elasticsearch客户端问题记录

问题分析:

在biz模块引入了5.5.2版本的es client jar,能找到对应的类

springboot集成elasticsearch客户端问题记录

查看api模块的war中的es client jar版本确实不是5.5.2,而是springboot默认的2.4.5,此版本确实是没有NetworkPlugin这个类的。

springboot集成elasticsearch客户端问题记录

这里涉及到maven的Dependency management 的两个作用,其中第二个方面就解释了为什么出现jar包版本的问题

1)It is a central place for defining versions of dependencies.

So when an artifact version is defined in the <dependencyManagement> section you can declare the dependency in your pom without defining the version, and the version defined in <dependencyManagement> will be used automatically.

Example 1

Let's say your parent pom defined the following

<dependencyManagement>

  <dependencies>

    <dependency>

      <groupId>com.mememe</groupId>

      <artifactId>mylib</artifactId>

      <version>1.1.12</version>

    </dependency>

  </dependencies>

</dependencyManagement>

Then if you define the following in your pom

<dependencies>

  <dependency>

    <groupId>com.mememe</groupId>

    <artifactId>mylib</artifactId>

  </dependency>

</dependencies>

Your project will automatically use version 1.1.12 as defined in the <dependencyManagement> section of your parent pom.

2)Overriding the versions of transitive dependencies.

If you have an artifact version defined in your <dependencyManagement> and one of your dependencies has a transitive dependency on the same artifact, the version of the artifact defined in your <dependencyManagement> section is used automatically.

Example 2

Let's say this artifact

<dependency>

  <groupId>com.youyou</groupId>

  <artifactId>yourlib</artifactId>

  <version>3.0.0</version>

</dependency>

Has this transitive dependency

<dependency>

  <groupId>com.morestuff</groupId>

  <artifactId>morelib</artifactId>

  <version>2.0.0</version>

</dependency>

Now let's say our parent pom defines this <dependencyManagement> section

<dependencyManagement>

  <dependencies>

    <dependency>

      <groupId>com.morestuff</groupId>

      <artifactId>morelib</artifactId>

      <version>2.5.2</version>

    </dependency>

  </dependencies>

</dependencyManagement>

Then if you define this dependency in your pom

<dependency>

  <groupId>com.youyou</groupId>

  <artifactId>yourlib</artifactId>

  <version>3.0.0</version>

</dependency>

Maven will override yourlib's dependency on morelib version 2.0.0 with morelib version 2.5.2.

参考:

https://stackoverflow.com/questions/49134849/maven-dependencytree-log-version1-compile-version-managed-from-version2

解决办法就是在api模块的pom文件中再一次添加依赖

springboot集成elasticsearch客户端问题记录

2.2 netty版本冲突

报错

Exception in thread "elasticsearch[_client_][management][T#1]" java.lang.AbstractMethodError:

springboot集成elasticsearch客户端问题记录

极光推送的客户端jar包也引入了netty

去掉即可

springboot集成elasticsearch客户端问题记录

点赞
收藏
评论区
推荐文章
Stella981 Stella981
2年前
SpringBoot 集成Mybatis 连接Mysql数据库
记录SpringBoot集成Mybatis连接数据库防止后面忘记1.添加Mybatis和Mysql依赖      <dependency    <groupIdorg.mybatis.spring.boot</groupId    <artifactIdmybatisspringbootst
Stella981 Stella981
2年前
SpringBoot整合自定义FTP文件连接池
说明:通过GenericObjectPool实现的FTP连接池,记录一下以供以后使用环境:JDK版本1.8框架:springboot2.1文件服务器:ServU1.引入依赖<!ftp文件上传<dependency<groupIdcommonsnet</groupId<artifact
Easter79 Easter79
2年前
SpringBoot自定义序列化的使用方式
场景及需求:项目接入了SpringBoot开发,现在需求是服务端接口返回的字段如果为空,那么自动转为空字符串。例如:\    {        "id":1,        "name":null    },    {        "id":2,        "name":"x
Stella981 Stella981
2年前
Spring Boot修改启动时默认的banner图案
动SpringBoot时,会默认展示如下图案及SpringBoot的版本信息,可以看到默认中的图案字体为Spring,当前的SpringBoot版本为SpringBoot2.1.6.RELEASE。!(https://oscimg.oschina.net/oscnet/upefbf9e41cbfe97b7b6c34517b4f432b524
Easter79 Easter79
2年前
Springboot整合elasticsearch以及接口开发
Springboot整合elasticsearch以及接口开发搭建elasticsearch集群搭建过程略(我这里用的是elasticsearch5.5.2版本)写入测试数据新建索引book(非结构化索引)PUThttp://192.168.100.102:9200/book
Stella981 Stella981
2年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Stella981 Stella981
2年前
Android So动态加载 优雅实现与原理分析
背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我
Easter79 Easter79
2年前
Springboot2 集成Swagger2,解决配置完成后不显示的坑
为新项目做准备重新搭建环境,决定使用Springboot2mybatis环境,使用shiro做权限管理,并搭配pagehelper,generator等。在配置Swagger2的时候出现访问时界面空白的坑,刚开始以为是配置的插件过多导致的不兼容,重新配置了其他环境,但问题依然存在,后来查找资料解决了问题。现在此作记录。目前使用Springboot版本为 
Easter79 Easter79
2年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Stella981 Stella981
2年前
SpringBoot自定义序列化的使用方式
场景及需求:项目接入了SpringBoot开发,现在需求是服务端接口返回的字段如果为空,那么自动转为空字符串。例如:\    {        "id":1,        "name":null    },    {        "id":2,        "name":"x
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k