Article directory
1. Reproducing the error
When connecting to hive
the database today, the following error was reported:
Right nowException in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;
2. Analysis errors
The error message means: Method com.google.common.util.concurrent.MoreExecutors
not found in class .sameThreadExecutor
Don't worry, let's look at at org.apache.curator.framework.listen.ListenerContainer.addListener(ListenerContainer.java:40)
this sentence again. It says that the error message is in ListenerContainer
the first line of the class 40
.
We click on the console and enter the ListenerContainer
row of the class 40
, as shown in the figure below:
As can be seen from the picture above, the color here sameThreadExecutor
is red, indicating that MoreExecutors
there is indeed no sameThreadExecutor
method in the class, so what should we do?
We click into the MoreExecutors
l category to view the comments on the first line, as shown below:
As can be seen from the above figure, MoreExecutors
the class is in Guava
, so pom.xml
the file is checked, as shown in the figure below:
As can be seen from the above picture, there are indeed no guava
dependent packages.
[Remarks]: The visual interface in the above picture is idea
the Maven Helper plug-in. For more idea plug-ins, please visit the link: More than a dozen commonly used and easy-to-use plug-ins of idea.
Since there is no dependent package, why are the classes in the package guava
introduced ? guava
We enter it in the text box above guava
, as shown below:
All the packages you will see hadoop-common,hive-exec,hive-jdbc
have imported guava
packages, and the versions of the imported guava
packages are different.
Therefore, we cannot use packages hadoop-common,hive-exec,hive-jdbc
introduced in packages guava
, but use our own guava
packages.
3. Fix errors
Therefore, we pom.xml
introduce the following packages in:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
Of course, you can eliminate the packages hadoop-common,hive-exec,hive-jdbc
introduced in the package guava
, or you can keep them.
For example, I want to eliminate the packages hadoop-common
introduced in the package guava
, as shown in the following code:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.3</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
After modification, restart, and this error does not appear:
At this time, we enter the position ListenerContainer
of the first line of the class 40
and find that the error is no longer reported, as shown in the following figure:
4. Important additions
Why are packages pom.xml
introduced in , and at the same time, packages in packages that are not removed can still run successfully?guava
hadoop-common,hive-exec,hive-jdbc
guava
We need to consider: dependencies maven
on the same package priority order loading version.pom
jar
4.1 POM in maven depends on the same jar package priority order to load versions
jar
When relying on multiple versions of a package, which version should be used first? The principles are as follows:
-
This level has priority over the superior level, and the superior level has priority over the subordinate level
-
The dependency version at this level takes precedence over the management version
-
The version loaded later in the same package overwrites the version loaded first
-
The upper-level management version and the current-level management version will overwrite the lower-level dependent versions.
-
Different lower-level jars depend on different versions. Prioritize loading the version in the lower-level jar first.
-
It has nothing to do with the size of the version number
-
This level cannot use lower-level management versions
4.2 Glossary of terms
-
Dependency version: refers to
dependencies
the direct dependency -
Management version: refers
dependencyManagement
to the version managed -
This level: refers to the current project
-
Superior: refers to
parent
dependentjar
-
Subordinate: refers to those referenced by this level
jar