错误一:
翻译:
改造heima-file-spring-boot-starter模块
新增依赖
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>7.1.0</version>
</dependency>
拷贝资料 中 config 及 service文件夹, 替换原有文件
加入自动配置
在resources中新建META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.heima.file.service.impl.OSSAliyunFileStorageService,com.heima.file.service.impl.MinIOFileStorageService
其他微服务使用
第一,导入heima-file-spring-boot-starter的依赖
第二,在配置中心 share-file.yml
中添加minio所需要的配置
#OSS配置
file:
oss:
bucket-name: <!-- 存储空间 -->
access-key-id: <!-- OSS密钥key -->
access-key-secret: <!-- OSS密钥 -->
endpoint: oss-cn-shanghai.aliyuncs.com
web-site: <!-- OSS访问前缀 -->
proxy-username: aliyun-sdk-java
socket-timeout: 10000
idle-connection-time: 10000
connection-request-timeout: 4000
max-connections: 2048
max-error-retry: 5
white-list: 127.0.0.1
connection-timeout: 10000
prefix: material
# minIO配置
minio:
accessKey: minio
secretKey: minio123
bucket: <!-- minIO中 bucket -->
endpoint: http://${spring.profiles.ip}:9090/
readPath: http://${spring.profiles.ip}:9090/
prefix: article
第三,在对应使用的业务类中注入FileStorageService,样例如下:
package com.heima.wemedia;
import com.heima.file.service.FileStorageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@SpringBootTest
@RunWith(SpringRunner.class)
public class MinIoTest {
// 指定MinIo实现
@Resource(name = "minIOFileStorageService")
FileStorageService fileStorageService;
// 不指定 beanName 注入的是OSS的实现
@Autowired
FileStorageService fileStorageService2;
@Test
public void uploadToMinIo() throws FileNotFoundException {
System.out.println(fileStorageService);
System.out.println(fileStorageService2);
// 准备好一个静态页
FileInputStream fileInputStream = new FileInputStream("D://list.html");
// 将静态页上传到minIO文件服务器中 文件名称 文件类型 文件流
fileStorageService.store("aa","list.html","text/html",fileInputStream);
}
}
错误二:
翻译: