tomcat webserver/servlet container/dispatcher servlet interaction in springboot - spring-boot

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.

Related

Dose Web Application Context and Servlet Application Context is same thing?

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.

Spring container , web container?

I have moderate understanding of Spring Framework, and in various books I read that Spring acts as a container.
Q1) What does it mean to say that Spring is a container?
Q2) Does spring as a container provide services like transactional, connection pooling etc.
Q3) what difference are in containers spring container vs web container -> It might be totally irrelevant comparsion, but if anyone can help me get this understand, really appreciate.
In spring: Spring container contains beans (Java objects that are subject to dependency-injection). It provides the space for residing these beans and maintains the life-cycle of the Java beans.
this is referred as Spring IOC container because of it provides Spring Inversion of Control.
You can learn more about Spring IOC container at http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html
Web Container, Specially Servlet containers contain servlets, filters, listeners, etc. and manages their state and lifecycle.That is the place where you can deploy your java based web applications.(any java web app e.g:- JSP/Servlet based web app, spring based web app etc...)
So keep it remember that these are two different things.

spring boot without web server but with management server

we have many services developed with spring boot, some are web services with a servlet container and some are services without a servlet container.
we don't use #EnableAutoConfiguration but we add only the auto configurations we need because our classpath is a mess and full auto configuration may create many beans we don't really need.
on services that don't need a servlet container we still want to have actuator and management server, so we register EndpointWebMvcAutoConfiguration but it has a condition on web application and does not create the management server.
of course i could just add EmbeddedServletContainerAutoConfiguration and just have a servlet container that does nothing but i don't like to do that.
Any idea how to cause spring boot to create the management server even on non web environment?
Thank you

Accessing Tomcat context parameter in Camel REST dsl

I am currently working on a set of REST resources that are deployed in a Tomcat servlet container. I have been using the Camel REST dsl (kickstarted by Spring) and it works very well. Now, I would like to get access to some parameters specified in the container's context.xml but havn't been able to figure out how to do that as I do not have access to the Servlet context in my route builder. Any suggestions?
Even though you are hosting your Spring-app on Tomcat, Camel is using a separate, internally loaded web server implementation for it's REST endpoints, e.g. Restlet or Spark-rest (for more infos check here). For that reason your Camel route is ignorant and entirely disconnected to your Tomcat let alone its Servlets contexts.

Spring Remote, configure httpinvoker and JAX on the same server

I have a server running on tomcat exposing Spring services using HttpInvoker.
I have exposed the methods of 5 services using HTTPInvoker.
This works very well.
The spring configuration is described in a file named remoting-servlet.xml; and the remoting servlet (DispatcherServlet) is described in the web.xml.
I now have an additional need to expose one additional service using JAX-WS this time (I will have C# clients).
I will use Spring support to JAX-WS.
I have the option to use the default deployment, or to use JAX-WS RI's to deploy this additional service to the same server as the remoting servlet.
I would prefer this last solution, because I would have only one server providing the remote services (whether they are web services or httpinvokers).
My question is: is this possible?
I think that I can I put the 2 servlets on the same port. But my issue is that it seems to me that I will have to provide 2 different application contexts. One for the DispatcherServlet, and one for the WSSpringServlet.
Is that correct?
Is it possible to put the WSSpringServlet context definition to the same file as the one for the httpinvokers (remoting-servlet.xml)?
Many thanks
Gilles

Resources