zhengjiaao / spring-boot-starter-minio

封装 minio 的 springboot 支持的依赖

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-boot-starter-minio

  • 封装最新的 minio 8.5.2 版本依赖 , 主要是简化配置、自动装配
  • 适配springboot(1.52.x)
spring-boot-starter-minio minio server springboot
8.5.2 RELEASE.2023-03-20T20-16-18Z 1.x
8.5.2 RELEASE.2023-03-20T20-16-18Z 2.x

安装 minio

使用

引入封装依赖:

    <dependency>
        <groupId>com.dist.zja</groupId>
        <artifactId>spring-boot-starter-minio</artifactId>
        <version>8.5.2</version>
    </dependency>

*.yaml配置

dist:
  minio:
    enabled: true  # 默认true
    secure: false  # 是否启动 https 访问, 默认 false
    endpoint: http://127.0.0.1
    port: 9000
    accessKey: admin
    secretKey: password
    default-bucket: default # 可选,仅支持小写字母,长度必须大于3个字符,默认桶会自动创建

bean类

    //桶操作类
    @Resource
    MinioBucketService minioBucketService;

    //对象操作类
    @Resource
    MinioObjectService minioObjectService;

    //客户端操作类
    @Resource
    MinioClient minioClient;

    //上传文件测试方法
    @Test
    public void test() throws Exception {
       /* ObjectWriteResponse response = minioClient.uploadObject(UploadObjectArgs.builder()
                .bucket("default")
                .object("a.jpg")  //存储对象id(文件的新名字)
                .filename("D:\\temp\\images\\a.jpg")
                .build());
        System.out.println(response.toString());*/

        //与上面一致,bucket=default
        minioObjectService.putObject("b.jpg", "D:\\temp\\images\\a.jpg");
    }

以上完成就可以测试上传文件了!

About

封装 minio 的 springboot 支持的依赖


Languages

Language:Batchfile 100.0%