1背景說明
服務端ES版本爲5.5.2,springboot版本爲1.5.6。
工程中添加如下依賴
2問題記錄
2.1 NetworkPlugin類找不到
報錯java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPlugin
和java.lang.NoClassDefFoundError: org/elasticsearch/plugins/NetworkPlugin
問題分析:
在biz模塊引入了5.5.2版本的es client jar,能找到對應的類
查看api模塊的war中的es client jar版本確實不是5.5.2,而是springboot默認的2.4.5,此版本確實是沒有NetworkPlugin這個類的。
這裏涉及到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.
參考:
解決辦法就是在api模塊的pom文件中再一次添加依賴
2.2 netty版本衝突
報錯
Exception in thread "elasticsearch[_client_][management][T#1]" java.lang.AbstractMethodError:
極光推送的客戶端jar包也引入了netty
去掉即可