[ERROR] Error creating bean with name 'aliCloudEdasSdk' defined in class path resource


環境

spring-cloud-alibaba-dependencies 2021.0.1.0

gulimall-common pom.xml

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>aliyun-oss-spring-boot-starter</artifactId>
</dependency>

....

<dependencyManagement>
	<dependenies>
		<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 pom.xml

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

錯誤提示

2022-04-18 21:15:08.104  WARN 79340 --- [           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;


***************************
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:/Users/xiaoming/local/.m2/repository/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:/Users/xiaoming/local/.m2/repository/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:/Users/xiaoming/local/.m2/repository/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

根據提示是因為 aliyun-java-sdk-core-3.4.0.jar 這個包沒有指定的方法

通過查看idea 查看 maven depenencies 依賴圖發現 aliyun-java-sdk-core 並沒有爆紅顯示沖突,
不過我們將鼠標放在 aliyun-java-sdk-core 看到版本顯示為 4.5.0,而點進去看到的版本卻是3.4.0。
說明 aliyun-oss-spring-boot-starter 中引入的是3.4.0版本,那么這個4.5.0版本在哪里呢?
在 aliyun-spring-boot-dependencies 依賴管理組件中發現引入的是4.5.0

解決辦法

上面已經找到沖突的包
那么只需要排除3.4.0 即可 (可不單獨再引入 4.5.0)

        <!-- 阿里雲 oss -->
        <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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM