SpringBoot 集成minio MinioClient无法依赖问题-已解决

 <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>4.9.0</version>
    </dependency>
    <dependency>
        <groupId>io.minio</groupId>
        <artifactId>minio</artifactId>
        <version>8.3.4</version>
    </dependency>

开始一直报错:
2022-03-01 15:31:44.041 WARN 66992 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘fileController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘fileServiceImpl’: Unsatisfied dependency expressed through field ‘minioTemplate’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘minioClient’ defined in class path resource [com/file/minio/MinioConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: **

Failed to instantiate [io.minio.MinioClient]: Factory method
‘minioClient’ threw exception;

** nested exception is java.lang.ExceptionInInitializerError

查看代码发现:SpringBoot 集成minio MinioClient无法依赖问题-已解决_第1张图片
也就是初始化 MinioClient 方法发生错误;

单独测试 初始化客户端

public class MAIN {
    public static void main(String[] args) throws Exception {
        MinioClient minioClient =  MinioClient.builder()
                .endpoint("127.0.0.1",9000,false)
                .credentials("minioadmin", "minioadmin")
                .build();
        createBucket(minioClient);
    }
    private static void createBucket(MinioClient minioClient) throws Exception{
        boolean exists = minioClient
                .bucketExists(BucketExistsArgs.builder().bucket("miniofile").build());
        if (exists) {
            return;
        }
        minioClient.makeBucket(MakeBucketArgs.builder().bucket("miniofile").build());
    }
}

报错信息:
SpringBoot 集成minio MinioClient无法依赖问题-已解决_第2张图片

Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.file.minio.MAIN.main(MAIN.java:9)
Caused by: java.lang.RuntimeException: Unsupported OkHttp library found. Must use okhttp >= 4.8.1
	at io.minio.S3Base.<clinit>(S3Base.java:100)
	... 1 more
Caused by: java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B

但是我的okHttp 版本是4.9.0 再看

NoSuchMethodError kotlin.collections.ArraysKt.copyInto([B[BIII)[B错误 怀疑是idea的依赖问题
SpringBoot 集成minio MinioClient无法依赖问题-已解决_第3张图片
新增

   <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>1.3.70</version>
  </dependency>

问题解决;

完整依赖

      <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>1.3.70</version>
        </dependency>
        <dependency>
            <groupId>io.minio</groupId>
            <artifactId>minio</artifactId>
            <version>8.3.4</version>
            <exclusions>
                <exclusion>
                    <groupId>com.squareup.okhttp3</groupId>
                    <artifactId>okhttp</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-stdlib</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

你可能感兴趣的:(spring,boot,java,spring)