在使用阿里云的oss对象上传服务的时候, 一直报错Caused by: java.lang.IllegalArgumentException: Oss endpoint can‘t be empty.
刚开始以为是版本有问题, 降低了springboot和springcloud的版本号
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
问题依旧存在, 然后排查是不是配置格式有误, access-key, secret-key, endpoint检查了好几次,都是对应的, 还是报错
之后看到有说新版本配置格式有变照着改了,还是没解决
旧版本:
spring:
cloud:
alicloud:
oss:
endpoint: xxx.aliyuncs.com
bucket: xxx
access-key: xxx
secret-key: xxx
新版本:
alibaba:
cloud:
access-key: xxx
secret-key: xxx
oss:
endpoint: xxx
bucket: xxx
后面以为xxx.aliyuncs.com前面要加上http://, 然后发现跟这无关
直到看到有位大佬发的一篇问答,描述的问题跟我遇到的一模一样, 加上了两个依赖, 问题才解决!!
原文链接: https://www.pudn.com/news/6228cc129ddf223e1ad0ec2d.html
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</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>
但是我后面在删掉这两个依赖之后,项目依旧能够启动成功
有人说springboot高版本会导致读不到nacos中的配置, 需要引入以下依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.4</version>
</dependency>
后续操作参考链接 : 谷粒商城使用springboot高版本导致Bootstrap不生效影响后续结果的坑(Oss endpoint can‘t be empty.)