服務端ES版本爲5.5.2,springboot版本爲1.5.6。java
工程中添加以下依賴spring
報錯java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPluginapi
和java.lang.NoClassDefFoundError: org/elasticsearch/plugins/NetworkPluginspringboot
問題分析:elasticsearch
在biz模塊引入了5.5.2版本的es client jar,能找到對應的類maven
查看api模塊的war中的es client jar版本確實不是5.5.2,而是springboot默認的2.4.5,此版本確實是沒有NetworkPlugin這個類的。ide
這裏涉及到maven的Dependency management 的兩個做用,其中第二個方面就解釋了爲何出現jar包版本的問題this
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.
參考:url
解決辦法就是在api模塊的pom文件中再一次添加依賴
報錯
Exception in thread "elasticsearch[_client_][management][T#1]" java.lang.AbstractMethodError:
極光推送的客戶端jar包也引入了netty
去掉便可