我正在使用WebFlux框架开发一个使用Spring Boot 2.0和Kotlin的应用程序.
我想在保存交易之前检查用户ID是否退出.我被困在一个简单的事情,如验证Mono是否为空.
fun createTransaction(serverRequest: ServerRequest) : Mono<ServerResponse> {
val transaction = serverRequest.body(BodyExtractors.toMono(Transaction::class.java))
transaction.flatMap {
val user = userRepository.findById(it.userId)
// If it's empty, return badRequest()
}
return transaction.flatMap { transactionRepository.save(it).then(created(URI.create("/transaction/" + it.id)).build()) }
}
Run Code Online (Sandbox Code Playgroud)
有可能做我想要的吗?
我正在使用 Spring Boot 2.1.3(使用标准的 Tomcat 嵌入式 Web 服务器)开发一个端点来上传图像,我想限制分段上传的大小。我可以使用以下属性轻松做到这一点:
spring:
servlet:
multipart:
max-file-size: 2MB
max-request-size: 2MB
Run Code Online (Sandbox Code Playgroud)
但是我总是得到一个 Spring 无法捕获的 500,因为 Tomcat 正在抛出异常并且请求没有到达我在 RestController 中的代码。
2019-03-02 10:12:50.544 ERROR [] [ o.a.c.c.C.[.[.[/].[dispatcherServlet]] [] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (3917946) exceeds the configured maximum (2097152)] with root cause
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because …Run Code Online (Sandbox Code Playgroud)