Spring boot, is it safe to use Spring MVC and Jersey together - spring

Is it safe, or even possible, to use Jersey and Spring MVC together via Spring boot starters? I realize Jersey registers it's own servlet (mapped to /* with default configuration) to handle requests, where as Spring MVC registers it's dispatcher servlet (mapped to / with default configuration).
Is it possible and safe to configure Jersey servlet to handle request under the /api path, where as Spring MVC would still handle all other requests, or would this lead to conflicts/instability, or considered as a bad design solution?

Related

Can we dispatch a request in Spring Web?

I'm referring to this question.
It's about OncePerRequestFilter. The answer says it's used when
the request could be dispatched to a different (or the same) servlet using the request dispatcher.
But as far as I know there's only one servlet in Spring Web which is the DispatcherServlet. What am I missing here?
We can define multiple servlets in one spring web application.
DispatcherServlet is the default servlet of spring implements.
Here is a example. https://www.baeldung.com/spring-web-contexts#parent-context

tomcat webserver/servlet container/dispatcher servlet interaction in springboot

what is the flow diagram of interactions between tomcat web server/servlet container and dispatcher servlet . tomcat servlet container is separate from spring IOC container or applicationcontext ?
Tomcat is a web server. It "knows" how to deal with web applications according to the web applications specification.
This specification defines means of servlets declaration, their order, etc. It also defines additional notions like filters, listeners, etc. This specification has nothing to do with spring. Basically, you can use tomcat to host the application with servlets, filters, listeners without spring dependencies, so you won't even have an application context.
With this in mind, Spring MVC (to which the Dispatcher Servlet actually belongs) is just a third-party among many others from the Tomcat standpoint.
DispatcherServlet is an ordinary servlet that the spring team has developed. It is an entry point to all spring infrastructure in web applications managed by a web server, it's a "glue" that acts as a "driver" - it loads the application context (all the beans), handles all the requests coming to the controllers, etc.

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

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?

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?).

use exceptionMapper for restcontroller so that jersey and restcontroller can coexist

I was using spring boot with Jersey 1. Used ExceptionMapper to handle the exceptions globally. Now we are planning to migrate to spring MVC for restful purpose. So, changing few of the endpoints to use dispatcher servlet.
Is there any way to handle all exceptions using exceptionMapper. There exists ControllerAdvice to handle exceptions globally for spring mvc but is there anyway I can use ExceptionMapper providers for time being?
Thank you

Resources