Java MINIO使用踩坑&解决

1.javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,3]
Message: 文档中根元素前面的标记必须格式正确。

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,3]
Message: 文档中根元素前面的标记必须格式正确。
	at io.minio.Xml.unmarshal(Xml.java:55)
	at io.minio.S3Base.getRegion(S3Base.java:698)
	at io.minio.S3Base.execute(S3Base.java:470)
	at io.minio.S3Base.executeHead(S3Base.java:728)
	at io.minio.MinioClient.bucketExists(MinioClient.java:1135)
	at com.glorypan.console.utils.FileUploader.main(FileUploader.java:25)
Error occurred: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,3]
Message: 文档中根元素前面的标记必须格式正确。
HTTP trace: null

 解决:

minio的官方文档有中英文两版,中文版的示例版本是7.0.2,英文版是8.3.0,如果是用docker直接pull的话,是最新版latest,pom文件引入依赖的时候要注意对应。

<dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>8.3.0</version>
</dependency>

并且 运行端口9000是api的端口9001是网页版的端口。

docker run -p 9000:9000 -p 9001:9001 --name minio -v D:\data:/data -e "MINIO_ROOT_USER=user" -e "MINIO_ROOT_PASSWORD=password" minio/minio server /data --console-address ":9001"

即创建minioclient时要用9000,而http://localhost:9001/用于网页访问控制台。

MinioClient minioClient = MinioClient.builder()
                    .endpoint("http://localhost:9000/")
                    .credentials("user", "password")
                    .build();

2. Unsupported OkHttp library found. Must use okhttp >= 4.8.1

Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.glorypan.console.utils.FileUploader.main(FileUploader.java:18)
Caused by: java.lang.RuntimeException: Unsupported OkHttp library found. Must use okhttp >= 4.8.1
	at io.minio.S3Base.<clinit>(S3Base.java:107)
	... 1 more
Caused by: java.lang.NoSuchMethodError: okhttp3.RequestBody.create([BLokhttp3/MediaType;)Lokhttp3/RequestBody;
	at io.minio.S3Base.<clinit>(S3Base.java:105)
	... 1 more

 解决:

minio依赖于okhttp,所以pom文件还需要引入一下okhttp。

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

3.Exception in thread "main" javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

Exception in thread "main" javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
	at java.base/sun.security.ssl.SSLSocketInputRecord.handleUnknownRecord(SSLSocketInputRecord.java:451)
	at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:175)
	at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:110)
	at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1369)
	at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1278)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:401)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:373)
	at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:379)
	at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:337)
	at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:209)
	at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
	at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
	at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
	at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
	at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
	at io.minio.S3Base.execute(S3Base.java:532)
	at io.minio.S3Base.getRegion(S3Base.java:694)
	at io.minio.S3Base.execute(S3Base.java:470)
	at io.minio.S3Base.executeHead(S3Base.java:728)
	at io.minio.MinioClient.bucketExists(MinioClient.java:1135)
	at com.glorypan.console.utils.FileUploader.main(FileUploader.java:25)
	Suppressed: javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
		... 30 more

解决:http别加s就行! 

MinioClient minioClient = MinioClient.builder()
                    .endpoint("http://localhost:9000/")
                    .credentials("user", "password")
                    .build();

minio guide:minio使用手册

  • 20
    点赞
  • 22
    收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
评论 6

打赏作者

Duck_Duck_

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值