Spring Cloud整合阿里云OSS存储上传图片(详细过程)
1.申请阿里云OSS账号
2.引入pom.xml依赖
<!-- 阿里云oss依赖 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<!-- 日期工具栏依赖 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
3.配置application.properties
#阿里云 OSS
#不同的服务器,地址不同
aliyun.oss.file.endpoint=your endpoint
aliyun.oss.file.keyid=your accessKeyId
aliyun.oss.file.keysecret=your accessKeySecret
#bucket可以在控制台创建,也可以使用java代码创建
aliyun.oss.file.bucketname=guli-file
aliyun.oss.file.keyid对应的这个AccessKey ID
aliyun.oss.file.endpoint对应的是上图Endpoint(地域节点)
点击查看Secret就能够查看aliyun.oss.file.keysecret,然后配置
4.编写工具类和Service、Controller代码
工具类代码:
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation