I have 2 questions.
Can a traditional servlet be used instead of a controller and served through DispatcherServlet?
How can i have a traditional servlet co-exist in a Spring-Boot-MVC (jar) application?
Related
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
Dose Web Application Context and Servlet Application Context is same thing?
I think these are same but different name.
Am I right?
If you speak about Servlet Context and not spring-servlet:
They are different things.
Every Java web applications that use Servlet technology will have a servlet context, doesn't related to Spring.
Servlet-context started when a Servlet application is deployed. Servlet Context holds all the configurations.
On the other hand, ApplicationContext is a Spring tech; i.e., it's a container to hold Spring beans.
So, for your questions, those are different.
BTW, spring-servlet it's a single front servlet handles all the HTTP requests of a particular web application. This front servlet has all the controls over incoming requests.
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.
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?
I would like to expose a Spring MVC controller in an application that will NOT be deployed in a web container like Tomcat. Is this possible? If so, can you please provide an example.
Spring boot has embedded servlet containers. This enables you to launch apps by executing a jar, instead of deployment to servlet container