Integrate MinIO in Spring Boot via a Custom Starter

Dependency Setup

Add the starter to your project's pom.xml. Its recommended to use version 1.0.0.

<dependency>
    <groupId>io.gitee.wangfugui-ma</groupId>
    <artifactId>minio-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>

Configuration

Define the connection details for your MinIO instance in application.yml or application.properties.

minio:
  endpoint: http://127.0.0.1:9000
  access-key: minioadmin
  secret-key: minioadmin
  • endpoint: The URL where your MinIO server is hosted.
  • access-key: The username for authenticating with the MinIO console.
  • secret-key: The password associated with the access key.

Injection and Usage

The starter auto-configures a template class named MinIOTemplate. You can inject it directly into your Spring components using @Autowired.

import org.springframework.beans.factory.annotation.Autowired;

public class StorageService {

    @Autowired
    private MinIOTemplate minioTemplate;

    public void checkBuckets() {
        // Logic to interact with MinIO
    }
}

Verification

To ensure the configuration is correct, execute a simple test to list existing buckets.

@Test
public void verifyBucketList() {
    List<String> buckets = minioTemplate.listBuckets();
    System.out.println("Available Buckets: " + buckets);
}

API Reference

The MinIOTemplate provides the following utility methods:

  1. void createBucket(String bucketName): Initializes a new bucket.
  2. void uploadFile(InputStream inputStream, String bucketName, String fileName): Stores a file stream into a specific bucket.
  3. List<String> listBuckets(): Retrieves the names of all buckets.
  4. List<Fileinfo> listFiles(String bucketName): Enumerates files and directories within a bucket.
  5. InputStream download(String bucketName, String fileName): Fetches a file as an input stream.
  6. void deleteBucket(String bucketName): Removes a bucket.
  7. void deleteObject(String bucketName, String fileName): Deletes a specific file from a bucket.
  8. void copyObject(String srcBucket, String srcFile, String destBucket, String destFile): Duplicates a file to a new location or name.
  9. String getObjectInfo(String bucketName, String fileName): Fetches metadata or info about a specific object.
  10. String getPresignedObjectUrl(String bucketName, String fileName, Integer expirySeconds): Generates a temporary URL for accessing a private file.
  11. List<Fileinfo> listAllFile(): Aggregates file info across all accessible buckets.

If the provided methods do not cover your specific use case, you can access the underlying native client via getMinioClient(), which returns an instance of io.minio.MinioClient.

Tags: Spring Boot MinIO starter java Object Storage

Posted on Fri, 04 Sep 2026 16:31:08 +0000 by Chris12345