跳到主要内容

· 阅读需 1 分钟

IDEA Datebase 突然查询数据库失败,提示08S01错误

[08S01] Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

· 阅读需 2 分钟

【转发】Stop Using TODO for Everything (停止使用 TODO 处理所有事情)

https://goldin.io/blog/stop-using-todo

很多程序员习惯在代码注释写 TODO,表示待完成的任务。作者建议不要再写 TODO,而用具体的任务替代,比如需要添加文档写"DOCME",需要添加测试写"TESTME"。

并不是说“注释不好”,或者“你应该只使用问题跟踪器”。而是有一些方便的,更具描述性的替代方案:

· 阅读需 2 分钟

[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>