Tag: spring webflux

Spring webflux beanvalidation不起作用

我正在尝试在Webflux中使用beanvalidation。 这是我迄今为止: @PostMapping(“contact”) fun create(@RequestBody @Valid contact: Mono) : Mono { return contact.flatMap { contactRepository.save(it) } .doOnError{ Error(“test”) } } validation不起作用…我期望的Error(“test”)将被显示… 有人有一个工作的例子(Java或Kotlin)? UPDATE 这是一个存储库,所以它可以复制: https : //github.com/jwz104/webflux-validation-test 请求: curl –request POST \ –url http://localhost:8080/tickets \ –header ‘content-type: application/json’ \ –data ‘{ “email”: “”, “name”: “”, “message”: “” }’ 将联系人重命名为ticket,但是一切仍然相同。

有什么办法可以实现春季webflux的分页和弹簧数据的反应

我试图了解Spring 5的反应部分。我已经创建了简单的rest端点,用于查找所有使用spring web-flux和spring data reactive(mongo)的实体,但是没有看到如何实现分页。 这是我在Kotlin的简单例子: @GetMapping(“/posts/”) fun getAllPosts() = postRepository.findAll() 这是否意味着反应终点不需要分页? 有什么办法从服务器端使用这个堆栈实现分页?

文件上传功能Webflux

我使用“Router Kotlin DSL”将原型迁移到Spring WebFlux(和Spring Boot)的功能变体。 现在我需要一些MIME类型multipart/form-data文件上传提示,而不是像application/json使用一些数据。 当我定义一个简单的路由器函数和一个像这样的处理程序时,我得到如下的堆栈跟踪: fun routes(handler: MultimediaHandler) = router { (accept(MediaType.MULTIPART_FORM_DATA) and "/multimedia").nest { PUT("/{id}", handler::upload) } } class MultimediaHandler { fun upload(request: ServerRequest): Mono<ServerResponse> { val id = request.pathVariable("id") return noContent().build() } } 堆栈跟踪: 13:43:29.713 ERROR [iurequest] [XNIO-1 I/O-3] UT005071: Undertow request failed HttpServerExchange{ PUT /multimedia/00000000-0000-0000-0000-000000000 001 request {Connection=[Keep-Alive], Accept-Encoding=[gzip,deflate], Content-Length=[1672], […]

Spring Web Flux(反应式)功能路由与Kotlin无法正常工作

你好有兴趣在Kotlin编写Spring应用程序的人。 我正在玩Spring Boot 2.0.0快照和spring-webflux 。 这段代码: @Component class TestRouter() : RouterFunction<ServerResponse> { override fun route(request: ServerRequest) = route(request) { "/".route { GET("/hello") { ServerResponse.ok().body(BodyInserters.fromObject("World")) } "/{id}".route { GET("/hello") { ServerResponse.ok().body(BodyInserters.fromObject("World ${request.pathVariable("id")}")) } } } } } 不按预期工作(至少如我所料:)) ➜ ~ curl -i http://localhost:8080/hello HTTP/1.1 200 OK transfer-encoding: chunked Content-Type: text/plain;charset=UTF-8 World 但: ➜ ~ curl -i […]

使用WebFlux WebTestClient和Kotlin输入干扰问题

我正在使用Spring Webflux和Kotlin构建一个新应用程序的原型。 Spring Webflux包含一个用于单元测试的WebTestClient。 根据文档,我应该能够测试像这样的REST调用的结果: @Test fun getVersion_SingleResult_ContentTypeJson_StatusCodeOk_ContentEqualsVersion() { //given var version = Version("Test", "1.0") val handler = ApiHandler(version!!) val client = WebTestClient.bindToRouterFunction(ApiRoutes(handler).apiRouter()).build() //expect val response = client.get().uri("/api/version/").exchange() response.expectStatus().isOk response.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8) response.expectBody(Version::class.java).isEqualTo(version) } 但是,我遇到了一些类型的干扰问题。 问题在于“expectBody”和“isEqualTo”的结合。 我得到的错误是: Kotlin:类型推断失败:没有足够的信息来推断fun inEqualTo(p0:Version!)中的参数T:T! 请明确指定。 使用的方法有以下签名: <B> WebTestClient.BodySpec<B, ?> expectBody(Class<B> var1); public interface BodySpec<B, S extends WebTestClient.BodySpec<B, S>> { <T extends S> […]

Kotlin协程和Spring Framework 5反应类型

Kotlin协程允许通过返回Deferred值来执行非阻塞代码。 这对于在使用阻塞方法(例如从库)中生成非阻塞代码非常有用。 Spring 5允许在框架中使用Mono和Flux 。 我所看到的最大兴趣是能够序列化这两种类型的实例,并在有人呼叫控制器端点时作为响应发回。 Spring 5的一个重要特点是对Kotlin(路由器,bean声明,…)有特定的支持,但是我找不到有关Kotlin协同程序和Spring 5反应类型之间可能的相互作用的信息。 有什么办法可以将这些功能的优点结合起来吗? 将Deferred转换为Mono / Flux ? 有一个Deferred作为响应类型的Spring控制器方法? 如果否,那么在这种情况下,如果我们有Spring 5反应类型,那么协程是否有意义呢?

Spring Boot + Kotlin注释错误(s)

我有一个写在Kotlin的Spring Boot 2.0.0.M2 (带WebFlux)应用程序。 我习惯于为测试用例定义/声明“注释”,以避免一些样板配置; 就像是: import java.lang.annotation.ElementType import java.lang.annotation.Inherited import java.lang.annotation.Retention import java.lang.annotation.RetentionPolicy import java.lang.annotation.Target … @Inherited @Target(ElementType.TYPE) @AutoConfigureWebTestClient // TODO: FTW this really does?! @Retention(RetentionPolicy.RUNTIME) //@kotlin.annotation.Target(AnnotationTarget.TYPE) //@kotlin.annotation.Retention(AnnotationRetention.RUNTIME) @ActiveProfiles(profiles = arrayOf("default", "test")) @ContextConfiguration(classes = arrayOf(Application::class)) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) annotation class SpringWebFluxTest …然后在我的测试中,我使用它: @SpringWebFluxTest @RunWith(SpringRunner::class) class PersonWorkflowTest { private lateinit var client: WebTestClient … 问题是 […]