最近在搭建公司的基礎框架,業務需求用到elasticsearch,所以需要整合到基礎框架里,供各業務線使用同時也便於管理,但在整合的過程中,出現了莫名的問題,同時maven的提示也不夠明確。
我的版本信息為 spring boot 2.1.0.RELEASE,elasticsearch 6.3.1,因為不同版本可能遇到的問題不一樣。
我的POM包引用為
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.0.RELEASE</version> <relativePath/> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency>
我的錯誤提示為如下圖,Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 2.1.0.RELEASE.,你能查詢的解決方案幾乎都是修改私有倉庫級別,但對我遇到的問題並不可行,
這里出現的問題跟私有庫沒關系,是包之間的不兼容造成的,解決步驟就是把出現問題的包一一排查,要求就是你要熟悉根據每步的提示,找到要排除的包,然后引用兼容的包,最后我的POM設置如下,同時解決elasticsearch 與redis 沖突的問題。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> <exclusions> <exclusion> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> </exclusion> <exclusion> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty4-client</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty4-client</artifactId> <exclusions> <exclusion> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> </exclusion> </exclusions> <version>6.3.1</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>6.3.1</version> <exclusions> <exclusion> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> </exclusion> <exclusion> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> </exclusion> <exclusion> <groupId>org.elasticsearch.plugin</groupId> <artifactId>transport-netty4-client</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> <version>6.3.1</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>6.3.1</version> </dependency>
然后運行 >mvn clean compile package -U,可以看到熟悉的BUILD SUCCESS。