SpringBoot所管理的依賴和需要的依賴沖突問(wèn)題及解決
背景
在使用springboot2.7.7 集成 elasticsearch7.9.3時(shí) 啟動(dòng)報(bào)錯(cuò)
Error creating bean with name 'client' defined in class path resource
[com/sgp/config/EsConfig.class]: Bean instantiation via factory method failed; nested exception
is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.elasticsearch.client.RestHighLevelClient]: Factory method 'client' threw exception; nested
exception is java.lang.NoClassDefFoundError:
org/elasticsearch/common/xcontent/DeprecationHandler at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.24.jar:5.3.24]
查看后發(fā)現(xiàn)當(dāng)前項(xiàng)目里面不僅有我引入的 es 7.9.3 版本的jar 還有springboot 2…7.7 所默認(rèn)加入7.13.1版jar,最初我的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>
<packaging>pom</packaging>
<modules>
<module>orders</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sgp</groupId>
<artifactId>es-study</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>es-study</name>
<description>es-study</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.9.3</version>
</dependency>
.....解決方案
網(wǎng)上有的說(shuō)像我以上的這種寫的指定依賴版本 就可以覆蓋springboot所管理的依賴,但很明顯在我這里并沒(méi)有用,于是通過(guò)在 <properties></properties> 里加上指定版本 然后再 dependency 中通過(guò)${}引入解決掉的 (先記錄一下 后面找到為什么的時(shí)候在寫原因)
<?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>
<packaging>pom</packaging>
<modules>
<module>orders</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sgp</groupId>
<artifactId>es-study</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>es-study</name>
<description>es-study</description>
<properties>
<java.version>1.8</java.version>
<elasticsearch.version>7.9.3</elasticsearch.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
.....總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java調(diào)用第三方http接口的常用方式總結(jié)
這篇文章主要介紹了Java調(diào)用第三方http接口的常用方式總結(jié),具有很好的參考價(jià)值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
springboot調(diào)用python文件的詳細(xì)方案
這篇文章主要為大家詳細(xì)介紹了springboot調(diào)用python文件的詳細(xì)方案,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-04-04
如何使用BeanUtils.copyProperties進(jìn)行對(duì)象之間的屬性賦值
這篇文章主要介紹了使用BeanUtils.copyProperties進(jìn)行對(duì)象之間的屬性賦值,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
Spring Security認(rèn)證提供程序示例詳解
這篇文章主要給大家介紹了關(guān)于Spring Security認(rèn)證提供程序的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Security具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
java實(shí)現(xiàn)RTF文件查看器(附帶源碼)
這篇文章主要介紹了一個(gè)基于?Java?Swing?的?RTF?文件查看器,既可作為輕量級(jí)桌面應(yīng)用,也可嵌入到更大規(guī)模的管理系統(tǒng)中,滿足用戶對(duì)?RTF?文檔的即時(shí)預(yù)覽、樣式保真和簡(jiǎn)單導(dǎo)航需求2025-06-06
模擬Spring的簡(jiǎn)單實(shí)現(xiàn)
本文的主要內(nèi)容就是學(xué)習(xí)Spring的開端,模擬一下Spring的實(shí)現(xiàn),感興趣的小伙伴可以參考一下2015-10-10
Spring使用RestTemplate模擬form提交示例
本篇文章主要介紹了Spring使用RestTemplate模擬form提交示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
SpringBoot 二維碼生成base64并上傳OSS的實(shí)現(xiàn)示例
本文主要介紹了SpringBoot 二維碼生成base64并上傳OSS的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05

