SpringBoot项目导入aliyun oss starter依赖后启动报错问题

 更新时间:2024年01月13日 09:35:03   作者:庸人冲  
这篇文章主要介绍了SpringBoot项目导入aliyun oss starter依赖后启动报错问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

描述

参考 官方文档 进行环境搭建:

版本信息:

  • spring boot: 2.6.6
  • spring cloud:2021.0.1
  • spring cloud alibaba:2021.0.1.0
  • aliyun-spring-boot-dependencies:1.0.0

公共项目 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>

其它项目 gulimall-product 中引入 gulimall-common:

<dependencies>
   <dependency>
      <groupId>com.yrc.gulimall</groupId>
      <artifactId>gulimall-common</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </dependency>
</dependencies>

启动 gulimall-product 项目,错误内容如下:

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 end

Process finished with exit code 1

原因

gulimall-common 项目中:

aliyun-oss-spring-boot-starter 默认引入的 aliyun-java-sdk-core 是 3.4.0 版本

-

但是 aliyun-spring-boot-dependencies 中对 aliyun-java-sdk-core 版本管理为:4.5.0

-

gulimall-product 引用了 gulimall-common 的依赖,但是没有引入 aliyun-spring-boot-dependencies 依赖管理,所以两个项目的 aliyun-java-sdk-core 版本不一致,就会会导致项目 gulimall-product 启动失败:

-

解决方法

在公共项目 gulimall-common 中排除 aliyun-oss-spring-boot-starter 默认的 aliyun-java-sdk-core ,单独引入 4.5.0 版本的 aliyun-java-sdk-core

<dependencies>
  <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>aliyun-oss-spring-boot-starter</artifactId>
      <exclusions>
      	<!--排除默认版本的依赖-->
          <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>

再次启动项目成功:

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • FasfDFS整合Java实现文件上传下载功能实例详解

    FasfDFS整合Java实现文件上传下载功能实例详解

    这篇文章主要介绍了FasfDFS整合Java实现文件上传下载功能实例详解,需要的朋友可以参考下
    2017-08-08
  • Javamail使用过程中常见问题解决方案

    Javamail使用过程中常见问题解决方案

    这篇文章主要介绍了Javamail使用过程中常见问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-08-08
  • Java中的位运算符、移位运算详细介绍

    Java中的位运算符、移位运算详细介绍

    这篇文章主要介绍了Java中的位运算符、移位运算,有需要的朋友可以参考一下
    2013-12-12
  • Windows下Dubbo+Zookeeper实现分布式部署教程

    Windows下Dubbo+Zookeeper实现分布式部署教程

    本文介绍了如何使用Dubbo和Zookeeper搭建分布式服务,包括环境准备、项目结构、依赖引入、接口与服务实现、注解配置及服务调用流程,适合初学者参考和实践
    2025-10-10
  • 微信公众号服务号推送模板消息设置方法(后端java)

    微信公众号服务号推送模板消息设置方法(后端java)

    公众号时经常会需要写推送消息,从网上找了一大堆,都不是很全,所以这篇文章主要介绍了微信公众号服务号推送模板消息设置方法的相关资料,需要的朋友可以参考下
    2023-02-02
  • Java之Spring框架使用及说明

    Java之Spring框架使用及说明

    Spring框架详解,涵盖IOC容器、依赖注入、AOP、事务管理及定时任务等简化企业级应用开发,通过示例代码展示Spring核心概念及实战用法,助力开发者提升开发效率和代码质量
    2026-05-05
  • Springsession nginx反向代理集成过程

    Springsession nginx反向代理集成过程

    这篇文章主要介绍了Springsession nginx反向代理集成过程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-04-04
  • SpringBoot集成xxl-job实现超牛的定时任务的步骤详解

    SpringBoot集成xxl-job实现超牛的定时任务的步骤详解

    XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅速、学习简单、轻量级、易扩展,现已开放源代码并接入多家公司线上产品线,开箱即用,本文给大家介绍了SpringBoot集成xxl-job实现超牛的定时任务,需要的朋友可以参考下
    2023-10-10
  • 使用EasyPOI实现多sheet动态列导出

    使用EasyPOI实现多sheet动态列导出

    这篇文章主要为大家详细介绍了如何使用EasyPOI根据指定时间范围创建动态列,以及如何将数据组织成符合要求的格式并导出,感兴趣的可以了解下
    2025-03-03
  • Java实现经典捕鱼达人游戏的示例代码

    Java实现经典捕鱼达人游戏的示例代码

    《捕鱼达人》是一款以深海狩猎为题材的休闲竞技游戏。本文将利用Java实现这一经典的游戏,文中采用了swing技术进行了界面化处理,需要的可以参考一下
    2022-02-02

最新评论