Control migration of a spring jersey app to webflux through a feature flag - spring-boot

We are thinking of how to migrate spring jersey app to webflux gradually, by converting jersey services to webflux controllers, and converting jersey filters to webfilters one by one, controlled by a feature flag. Since webflux can run on modern servlet containers, I am thinking of mapping the original path to a servlet that just does the forwarding based on the value of the feature flag. However, as I understand, spring boot does not allow webflux to co-exist with spring MVC/Jersey. What's a best way to migrate existing app to webflux?

Related

Spring Boot and Spring MVC are actually frameworks or not?

I know that the Spring Framework is a Framework, but the emergence of Spring Boot and Spring MVC makes me confused whether it is a framework or just one of the modules that Spring Framework has?
Yes.Spring is the most popular application framework for develop java base web application and spring framework core feature can be use any java application.
Also many people refer to Spring web MVC as a framework.
There is nothing wrong with that.
In other words, the spring web MVC is a part of the spring framework that is designed to implement web part in our application.
spring framework img
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.
Spring Boot Framework is widely used to develop REST APIs
If analyzed in depth Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications.
In short, Spring Boot is the combination of Spring Framework and Embedded Servers.
spring boot img
read more Web MVC
read more Spring boot

Spring mvc and webflux in 1 spring boot application

I got below instruction from spring boot doc:
Adding both spring-boot-starter-web and spring-boot-starter-webflux modules in your application results in Spring Boot auto-configuring Spring MVC, not WebFlux. This behavior has been chosen because many Spring developers add spring-boot-starter-webflux to their Spring MVC application to use the reactive WebClient. You can still enforce your choice by setting the chosen application type to SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)
My question is:
What if my application contains both MVC services and webflux services?
Is it supported?
For example:
I may have some existing admin service which is MVC based. Now I want to add some new services with webflux style.
No, this is not supported. Spring MVC and Spring WebFlux have different runtime models and don't support the same servers (for example, Spring WebFlux can be run with Netty, Spring MVC cannot).
Also, Spring MVC and Spring WebFlux are full web frameworks, meaning each has its own infrastructure that somehow duplicates the other. Deploying both in the same app would make it difficult to map requests (which requests should go where?).

Spring contract-first REST

I have a Spring web application - which doesn't use Spring-based GUI, but Wicket - and I would like to build contract-first REST services.
I already have a contract defined in Swagger and I generate model and API artifacts. Swagger codegen generates either Spring Boot artifacts, or Spring MVC ones.
My intention is to use ideally just a model, and maybe API (controllers) from this generated code. But up to my knowledge/research, there is no simple way to have just simple REST service without MVC/Boot boilerplate.
Therefore my questions are:
Is it possible to build lightweight Spring-based REST service, without having "heavy" dependency of full Spring MVC/Spring Boot?
If not, which approach is more lightweight? Spring Boot, or Spring MVC?
You are misinterpreting the Spring ecosystem.
Spring MVC is THE rest web and web service library within Spring portfolio.
The same way as Spring-WS is THE soap web service library.
They are very similar in architecture and style of use.
The fact that Spring MVC is bundled with Spring Framework does not change the situation.
Spring Boot does not bring any new REST offering. It is just a bootstrap mechanism to start Java web server with web app already deployed from a plain main() method. Therefore if you see "Building REST web services with Spring Boot", it just means that it is Spring MVC bootstrapped by Spring Boot.
Therefore, the question to what is more lightweight is straightforward: Spring MVC.
To answer the question #2:
The usage of Spring MVC is more lighweight, then usage of Spring Boot:
Size of the WAR archive:
6,1 MB for Spring MVC
9,2 MB for Spring Boot
Number of libraries in WAR archive:
12 for Spring MVC
28 for Spring Boot

Can you use (any) Spring's functionality outside of Spring (Boot)?

I have just built a RESTful web service with Spring Boot.
I now want to utilise the RESTful web service and start making calls to it by building a java console application (eventually adding GUI and security).
I was wondering if I can use any of the Spring functionality outside of the Spring (Boot) environment and use it in my java console application? For example, can I use Spring's RestTemplate in my non-Spring java application to make the REST api calls? I am new to Spring and I want to stick as close to Spring as possible. I think you can't, but I just want to make sure.
If not possible, I know you can create non-web application with Spring. Is it possible to integrate a GUI? Might not be best practice, just exploring what is possible and conventional.
Spring Boot is not coupled, in any way, to an application type. You can run command-line only apps, batch apps, web apps or any other kind of apps with it. You can even benefit from Spring Boot's auto-configuration.
In the case of the RestTemplate you may want to import spring-web directly rather than spring-boot-starter-web. Or you could add the starter and exclude the embedded container (spring-boot-starter-tomcat). Spring Boot will auto-adapt and not start an embedded web server in that case.

how to use web.xml file into spring boot application without extend WsConfigurerAdapter?

I am using spring-boot to develop webservices, but I don't want to use WsConfigurerAdapter to define a WSDL and all, because I want to deploy my war into WAS7 and it does not support Servlet 3.0. So how would I add a web.xml configuration into my application.
Spring Boot doesn't support Servlet 2.5 out of the box, however you can use Spring Boot Legacy to get things working. Take a look at the Google App Engine sample application for an example of how to use Spring Boot Legacy and web.xml.
You may also be interested in this Spring Boot issue which is proposing to make Spring Boot Legacy an official part of Spring Boot.

Resources