Does spring-boot-starter-webflux include spring-boot-starter-web? - spring-webflux

Can I use the existing spring-boot-starter-web coding scheme with only spring-boot-starter-webflux added?? without spring-boot-starter-web.

spring-boot-starter-webflux provides the relevant dependencies for a Spring WebFlux application, from Jackson to the spring-webflux module for annotation and functional programming models.
spring-boot-starter-web does the same for Spring MVC.
Having both on the classpath means that you want a Spring MVC app and still use the new WebClient provided by Spring WebFlux in that application.
As mentioned in the Spring Boot reference documentation, you should add spring-boot-starter-webflux if you want to create a Spring WebFlux app and avoid adding spring-boot-starter-web.

Related

How to use request and session scopes in spring-webflux (as of latest releases)

I am developing a rest web service using reactive programming through spring-webflux(Spring Boot 2.1 and Spring Framework 5.1). I need to create components having request level scope. #Scope annotation is suggested for spring MVC applications. But I found that the same doesn't work with webflux application.
Is there an equivalent feature available in webflux, as of latest release?
If not, what shall be the workaround here to create a new instance of a component on every incoming request?
I am trying to avoid use of new operator.
Thank you for the suggestions.
Unfortunately you cannot use request scopes in spring-webflux like in spring MVC applications. The main reason being, they use ThreadLocals which cannot be used by spring-webflux as work can be done on any thread at any time.
Spring webflux uses project-reactor at its core. So you can use Reactor Context which allows you to share data in your reactive pipeline.

How Spring MVC works with mybatis?

I am new to Spring MVC and i completed one crud operation using Spring MVC with JDBC template in Maven, now I am going to use of myBatis for same project.
But i don't know about myBatis , what is the advantage of using myBatis instead of JDBC and how it works with Spring MVC.
MyBatis has an official demo app called JPetStore which is based on Stripes.
There are several user contributed variants and this one is based on Spring MVC.
If you are using Spring Boot, check out this demo project which uses MyBatis Spring Boot Starter to make configuration easier.

WebFlux web and webflux starter

I created a Spring boot 2.0.0.M7 project with the webflux starter because I want to use all the asynchronous and the non-blocking capabilities.
I added the server.servlet.context-path but it does not work if I don't add the web starter as well.
If I add both starters can I have issues with the non-blocking functionality?
I executed some stress tests with Gatling and I have received the same scores removing the web starter or adding it.
Any help with this?
If you add both spring-boot-starter-web and spring-boot-starter-webflux to your application, Spring Boot will configure it as a Spring MVC app.
This is intentional as many Spring MVC will get the webflux dependency to leverage the new WebClient in their MVC apps. Also, as of Spring Framework 5, Spring MVC knows how to handle a few cases with Flux at the controller level.
You can always force your choice like this:
SpringApplication app = new SpringApplication(MyApplication.class);
app.setWebApplicationType(WebApplicationType.REACTIVE);
app.run(...);
In your case, this is not about forcing a choice but rather using something that's not supported in WebFlux.
The server.servlet.context-path configuration property is Servlet-specific, so it won't work with WebFlux. Currently Spring Boot does not support war deployment nor multiple web contexts for WebFlux applications. So there's no point in offering such a property.
The runtime model difference between "Servlet-based" and Reactive runtime with Spring can be quite subtle, and I encourage you to watch a talk that describes those choices. The short answer is: if you're using Spring MVC with async types (DeferredResult, Flux or SseEmitter) things will be async but reading and writing will still be blocking.
Properly benchmarking that is quite hard, but the results you're seeing are somehow expected. Running locally server+client, no latency involved, looking at raw throughput - all of those constraints should not be in favour of the reactive model which has a concurrency cost. If anything, this benchmark shows that the reactive stack is quite optimized already, even for non-ideal use cases!

Spring WebFlux - no JSP support?

I was trying to configure Spring WebFlux with JSP. I don't see any View class for supporting JSTL views in Spring WebFlux.
Does this mean that we can't develop a JSP application using Spring WebFlux?
Thanks, AJ
WebFlux is not tied to the Servlet specification so JSP support cannot be consistently implemented across deployment options.

How to design filters/interceptors in Spring Webflux?

While migrating my project from Spring MVC architechture to the Webflux framework, I encountered some confusion. I want to understand what are the corresponding equivalents (if any) or alternatives of the configurations used to perform Authorization/Form Validation in MVC, that will apply for WebFlux ?