brief introduction
My autumn recruitment is basically over. The busiest time period is August and September. There is basically no written examination / interview in October, or I am really tired and don't want to continue the autumn recruitment. I want to lie down. Some of them really take the initiative to end the process
Because of the experience of qiuzhao, I now know more about my knowledge system and what I need to add, because qiuzhao is really suffering. It is really uncomfortable and empty to change from that state all at once.
All occasionally take some time to continue their previous studies, such as what I want to say Grain mall , here is a question that has bothered me for a long time
explain
There are two links below about the project
Station B: https://www.bilibili.com/video/BV1np4y1C7Yf
Notes: https://www.yuque.com/zhangshuaiyin/guli-mall/wrbzgy
problem
The problem I encountered is that the version specified by the < Properties > tag of the subproject of p125's SpringBoot integration ElasticSearch does not take effect.
Elasticsearch rest high level client needs to be introduced, and the version is determined according to your own ES
<dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>7.11.1</version> </dependency>
The problem with direct introduction is that the ES component version of SpringBoot is different from what we need, which will cause some problems (as shown in the figure below, we expect the result, but the ES version of SpringBoot is in the red box before). There will be problems when using some APIs
The procedure in the video is to configure the < Properties > tag and add the ES version
Find the ES version configuration in the SpringBoot I use. According to the proximity principle, we only need to make the following configuration in the project (this is also the method in the video)
<properties> <elasticsearch.version>7.11.1</elasticsearch.version> </properties>
But it didn't come up with the result I expected. I tried it many times, but it was wrong. Although the corresponding package solution can be introduced violently (that is, add the following code), I don't think it is the best solution
<dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>${elasticsearch.version}</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> <version>${elasticsearch.version}</version> </dependency>
What's wrong
Is the proximity principle wrong? Is there a bug in IDEA?
Various ideas appeared, but they couldn't be solved
At this time, I thought that although I learned according to the video and typed the code myself, I am not invariable. For example, the whole project architecture, because I have a certain foundation, I will make small reconstruction of the parent-child project, and manage some public version dependencies through the parent project
So I took a new project to do the experiment. I completely followed the video, that is, the SpringBoot project, introduced elasticsearch rest high level client, and configured the < Properties > version
Sure enough, it is the result I expected. Now the problem is obvious. The problem is that the parent project of my search sub project is a large parent project I configured, which contains many other dependencies. It may be the problem here
Final solution
Parent pom
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wnh.gulimall</groupId> <artifactId>gulimall</artifactId> <version>0.0.1-SNAPSHOT</version> <name>gulimall</name> <description>Demo project for Spring Boot</description> <packaging>pom</packaging> <modules> <module>gulimall-coupon</module> <module>gulimall-member</module> <module>gulimall-order</module> <module>gulimall-product</module> <module>gulimall-ware</module> <module>renren-fast</module> <module>gulimall-common</module> <module>gulimall-gateway</module> <module>gulimall-third-part</module> <module>renren-generator</module> <module>gulimall-search</module> </modules> <!-- unified management jar Package version --> <properties> ... <elasticsearch.version>7.11.1</elasticsearch.version> </properties> <!-- After the sub module inherits, it provides the following functions: locking the version+son modlue Do not write groupId and version --> <dependencyManagement> <dependencies> ... <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>${elasticsearch.version}</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>${elasticsearch.version}</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> <version>${elasticsearch.version}</version> </dependency> ... </dependencies> </dependencyManagement> ... <!-- Some public dependencies --> <dependencies> ... </dependencies> </project>
The sub pom is very simple. You can directly import it without using the version
<dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> </dependency>
supplement
Some dependency conflicts in the project were also found during problem solving. It is recommended to use Maven Helper, a plug-in of IDEA, to solve them
I've been using this plug-in for a long time, but I haven't used it. I just practice it here
As above, there are two options under pom: Text and Dependency Analyzer
Text display pom content
Dependency Analyzer dependency analysis, which analyzes the problems between pom dependencies and displays the conflicting items
If you don't think the dependency relationship is clear, you can find Show Dependencies... On the Maven toolbar on the right to display the dependency diagram, in which the conflicts will be marked in red, which is very convenient
Conflicts can be resolved by excluding certain dependencies
summary
The recent learning state is not good. I have been lying for a long time after the autumn move. The state is really not as good as before. I hope I can recover slowly and find a Balance to adapt to myself