Skip to content

Tag: spring-webflux

How to add @RestController to spring-webflux apps?

The annotation @RestController cannot be resolved when only adding spring-boot-starter-webflux as maven dependency: pom.xml: What is missing here? According to many resources out there (eg https://medium.com/javarevisited/basic-introduction-to-spring-webflux-eb155f501b17), the webflux dependency should be sufficient for a webflux-webservice in spring-boot. Answer RestController annotation is part of org.springframework:spring-web: dependency org.springframework:spring-web dependency is part of org.springframework.boot:spring-boot-starter-webflux jar so it should get resolved. You can check

How to deploy a Spring-Boot-Webflux application to Tomcat standalone server?

A normal spring-web application can be deployed to tomcat standalone as war file as follows: Question: how can I deploy such an application after migrating to spring-webflux to tomcat? Docs say: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-httphandler To deploy as a WAR to any Servlet 3.1+ container, you can extend and include AbstractReactiveWebInitializer in the WAR. That class wraps an HttpHandler with ServletHttpHandlerAdapter and registers

How do I increase the default timeout in the Cassandra Java driver using the DriverConfigLoader?

Small question regarding a Spring Webflux Reactive Cassandra application please. On a setup Spring Boot 2.6.4 with Webflux and reactive Cassandra, I am using the app to insert some data in Cassandra tables. Things works fine, until when there is a higher load, I am seeing an issue (stack trace attached) The thing is, reading some documentation, I thought this

How to setServletPath() in Spring Junit WebTestClient?

This creates a MockHttpServletRequest that is send to the @RestContoller servlets. Problem: my servlets make use of HttpServletRequest.getServletPath(), but which is always empty using the WebTestClient approach above. Question: how can I explicit set the servletPath in my junit tests? Answer I could solve it as follows, but as this is really hacky, I’d still appreciate a proper solution.

Spring: re-initialized a bean

This is my Spring bean in the configuration class that creates a gRPC ManagedChannel: The controller method is provided below: The service class is: For each request, I create a new ManagedChannel in the service method processRequest and shut it down using the method called shutdownManagedChannel. Earlier, I try to use the @Autowired for the managed channel as below: This

How to consume infinite flux multiple times

This is what I’m trying to achieve: When somebody requests http://localhost/runIt, I would like to return data from cache that would be refreshed every 6 seconds. Below, I have a flux (always same one that is stored in map) that is first time instantiated and starts emitting numbers 0,1,2,3,4… to infinity. Is it possible to make this Spring MVC Controller

Building a Recursive Data Structure with Spring WebFlux

I have a REST API that is built with the Spring WebFlux framework, and I have an endpoint which returns a Flux<ChannelResponse>, where ChannelResponse is a tree-structured object, as shown below: Now, I don’t have much experience with the reactive programming paradigm, but this is how I would implement such an endpoint with synchronous logic, such that each top-level channel