SpringBoot + MinIO 轻松构建对象存储服务,支持私有化部署!
    		       		warning:
    		            这篇文章距离上次修改已过428天,其中的内容可能已经有所变动。
    		        
        		                
                以下是一个使用Spring Boot和MinIO构建对象存储服务的简化示例:
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
@Configuration
public class MinioConfig {
 
    @Value("${minio.url}")
    private String minioUrl;
 
    @Value("${minio.accessKey}")
    private String minioAccessKey;
 
    @Value("${minio.secretKey}")
    private String minioSecretKey;
 
    @Bean
    public MinioClient minioClient() {
        try {
            return MinioClient.builder()
                    .endpoint(minioUrl)
                    .credentials(minioAccessKey, minioSecretKey)
                    .build();
        } catch (Exception e) {
            throw new RuntimeException("Error while creating MinioClient", e);
        }
    }
}在这个配置类中,我们定义了MinIO客户端的Bean,它会在Spring Boot应用程序启动时初始化。minioUrl、minioAccessKey和minioSecretKey是通过属性文件或环境变量注入的,以保证安全性和灵活性。
这个配置类可以作为构建MinIO客户端实例的起点,并且可以根据具体需求进行扩展,比如添加与MinIO交互的服务组件。
评论已关闭