【发布时间】:2021-01-16 00:07:54
【问题描述】:
在 Spring Boot 2.3 中,我使用了以下 Kotlin 代码
val mvcResultImage = this.mockMvc!!.perform(MockMvcRequestBuilders.multipart("/somepath)
.file("files[]", imageFile.getBytes())
.characterEncoding("UTF-8"))
.andReturn()
在带有函数的控制器的集成测试中
@PostMapping(path = ["/somepath"],
consumes = [MediaType.MULTIPART_FORM_DATA_VALUE],
produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
fun createFromBytes(@RequestParam("files[]") file: MultipartFile): ResponseEntity<Any> {
...
}
在 2.3 中,我能够在控制器函数中处理请求,而在 2.4 中,控制器函数引发 org.springframework.web.multipart.support.MissingServletRequestPartException 和消息 Required request part 'files[]' is not present 并导致 HTTP 响应代码 400。
我在迁移指南和此版本更改的已处理问题列表中找不到任何内容。
在控制器和请求中重命名为 file 没有帮助,我不记得为什么我在使用 2.3 的代码中添加了 [],但我认为有必要让它工作。
我通过带有spring-boot-starter-parent:2.4.1 的maven 父机制使用Spring Boot。
【问题讨论】:
标签: spring spring-boot kotlin multipartform-data http-request-parameters