SpringBoot項(xiàng)目導(dǎo)入aliyun oss starter依賴后啟動(dòng)報(bào)錯(cuò)問題
描述
參考 官方文檔 進(jìn)行環(huán)境搭建:
版本信息:
- spring boot: 2.6.6
- spring cloud:2021.0.1
- spring cloud alibaba:2021.0.1.0
- aliyun-spring-boot-dependencies:1.0.0
公共項(xiàng)目 gulimall-common 中引入 aliyun oss starter :
<dependencies>
<!--省略其它依賴-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>aliyun-oss-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.0.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>aliyun-spring-boot-dependencies</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
其它項(xiàng)目 gulimall-product 中引入 gulimall-common:
<dependencies>
<dependency>
<groupId>com.yrc.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
啟動(dòng) gulimall-product 項(xiàng)目,錯(cuò)誤內(nèi)容如下:
2022-04-10 11:13:31.081 WARN 22884 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aliCloudEdasSdk' defined in class path resource [com/alibaba/cloud/spring/boot/context/autoconfigure/EdasContextAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.cloud.context.edas.AliCloudEdasSdk]: Factory method 'aliCloudEdasSdk' threw exception; nested exception is java.lang.NoSuchMethodError: com.aliyuncs.profile.DefaultProfile.getHttpClientConfig()Lcom/aliyuncs/http/HttpClientConfig;
2022-04-10 11:13:31.085 INFO 22884 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-04-10 11:13:31.095 INFO 22884 --- [ main] ConditionEvaluationReportLoggingListener :Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-04-10 11:13:31.116 ERROR 22884 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :***************************
APPLICATION FAILED TO START
***************************Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.alibaba.cloud.context.AliCloudSdk.<init>(AliCloudSdk.java:76)
The following method did not exist:
com.aliyuncs.profile.DefaultProfile.getHttpClientConfig()Lcom/aliyuncs/http/HttpClientConfig;
The calling method's class, com.alibaba.cloud.context.AliCloudSdk, was loaded from the following location:
jar:file:/D:/maven/respository/com/alibaba/cloud/alicloud-context/1.0.5/alicloud-context-1.0.5.jar!/com/alibaba/cloud/context/AliCloudSdk.class
The called method's class, com.aliyuncs.profile.DefaultProfile, is available from the following locations:
jar:file:/D:/maven/respository/com/aliyun/aliyun-java-sdk-core/3.4.0/aliyun-java-sdk-core-3.4.0.jar!/com/aliyuncs/profile/DefaultProfile.class
The called method's class hierarchy was loaded from the following locations:
com.aliyuncs.profile.DefaultProfile: file:/D:/maven/respository/com/aliyun/aliyun-java-sdk-core/3.4.0/aliyun-java-sdk-core-3.4.0.jar
Action:Correct the classpath of your application so that it contains compatible versions of the classes com.alibaba.cloud.context.AliCloudSdk and com.aliyuncs.profile.DefaultProfile
2022-04-10 11:13:31.117 WARN 22884 --- [ Thread-16] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Start destroying common HttpClient
2022-04-10 11:13:31.118 WARN 22884 --- [ Thread-16] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Destruction of the endProcess finished with exit code 1
原因
gulimall-common 項(xiàng)目中:
aliyun-oss-spring-boot-starter 默認(rèn)引入的 aliyun-java-sdk-core 是 3.4.0 版本

但是 aliyun-spring-boot-dependencies 中對(duì) aliyun-java-sdk-core 版本管理為:4.5.0

gulimall-product 引用了 gulimall-common 的依賴,但是沒有引入 aliyun-spring-boot-dependencies 依賴管理,所以兩個(gè)項(xiàng)目的 aliyun-java-sdk-core 版本不一致,就會(huì)會(huì)導(dǎo)致項(xiàng)目 gulimall-product 啟動(dòng)失敗:

解決方法
在公共項(xiàng)目 gulimall-common 中排除 aliyun-oss-spring-boot-starter 默認(rèn)的 aliyun-java-sdk-core ,單獨(dú)引入 4.5.0 版本的 aliyun-java-sdk-core :
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>aliyun-oss-spring-boot-starter</artifactId>
<exclusions>
<!--排除默認(rèn)版本的依賴-->
<exclusion>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!--引入4.5.0 版本依賴-->
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.0</version>
</dependency>
</dependencies>
再次啟動(dòng)項(xiàng)目成功:

總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
FasfDFS整合Java實(shí)現(xiàn)文件上傳下載功能實(shí)例詳解
這篇文章主要介紹了FasfDFS整合Java實(shí)現(xiàn)文件上傳下載功能實(shí)例詳解,需要的朋友可以參考下2017-08-08
Java中的位運(yùn)算符、移位運(yùn)算詳細(xì)介紹
這篇文章主要介紹了Java中的位運(yùn)算符、移位運(yùn)算,有需要的朋友可以參考一下2013-12-12
Windows下Dubbo+Zookeeper實(shí)現(xiàn)分布式部署教程
本文介紹了如何使用Dubbo和Zookeeper搭建分布式服務(wù),包括環(huán)境準(zhǔn)備、項(xiàng)目結(jié)構(gòu)、依賴引入、接口與服務(wù)實(shí)現(xiàn)、注解配置及服務(wù)調(diào)用流程,適合初學(xué)者參考和實(shí)踐2025-10-10
微信公眾號(hào)服務(wù)號(hào)推送模板消息設(shè)置方法(后端java)
公眾號(hào)時(shí)經(jīng)常會(huì)需要寫推送消息,從網(wǎng)上找了一大堆,都不是很全,所以這篇文章主要介紹了微信公眾號(hào)服務(wù)號(hào)推送模板消息設(shè)置方法的相關(guān)資料,需要的朋友可以參考下2023-02-02
SpringBoot集成xxl-job實(shí)現(xiàn)超牛的定時(shí)任務(wù)的步驟詳解
XXL-JOB是一個(gè)分布式任務(wù)調(diào)度平臺(tái),其核心設(shè)計(jì)目標(biāo)是開發(fā)迅速、學(xué)習(xí)簡單、輕量級(jí)、易擴(kuò)展,現(xiàn)已開放源代碼并接入多家公司線上產(chǎn)品線,開箱即用,本文給大家介紹了SpringBoot集成xxl-job實(shí)現(xiàn)超牛的定時(shí)任務(wù),需要的朋友可以參考下2023-10-10
使用EasyPOI實(shí)現(xiàn)多sheet動(dòng)態(tài)列導(dǎo)出
這篇文章主要為大家詳細(xì)介紹了如何使用EasyPOI根據(jù)指定時(shí)間范圍創(chuàng)建動(dòng)態(tài)列,以及如何將數(shù)據(jù)組織成符合要求的格式并導(dǎo)出,感興趣的可以了解下2025-03-03
Java實(shí)現(xiàn)經(jīng)典捕魚達(dá)人游戲的示例代碼
《捕魚達(dá)人》是一款以深海狩獵為題材的休閑競技游戲。本文將利用Java實(shí)現(xiàn)這一經(jīng)典的游戲,文中采用了swing技術(shù)進(jìn)行了界面化處理,需要的可以參考一下2022-02-02

