如何解决Spring Boot Web 测试客户端模拟多部分文件不起作用
Mockmultipartfile file = new Mockmultipartfile("files","Test.txt","text/plain",this.getClass().getResourceAsstream("/Test.txt"));
webTestClient.post()
.uri("/foo").header("test","1")
.header("test1","1")
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData("files",file))
.exchange()
.expectStatus().isOk();
出现异常:
org.springframework.core.codec.CodecException:
Type deFinition error: [simple type,class java.io.ByteArrayInputStream];
nested exception is com.fasterxml.jackson.databind.exc.InvalidDeFinitionException:
No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer
(to avoid exception,disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
(through reference chain: org.springframework.mock.web.Mockmultipartfile["inputStream"])
在我的邮递员那里工作得很好。请找到随附的邮递员截图enter image description here
解决方法
webTestClient.post()
.uri("/foo").header("test","1")
.header("test1","1")
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData("files",this.getClass().getResource("/Test.txt")))
.exchange()
.expectStatus().isOk();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。