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

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.

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.

Serving traditional servlet through DispatcherServlet

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?

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 with Jersey + Jetty challenge

I'm new to dependency injection w/ Spring and am facing a seemingly challenging scenario.
My application receives data from a legacy system over a plain old socket, does Interesting Things (tm) with the data, then uses an embedded Jetty instance to pump out Really Interesting Results (tm) via HTML5 Web Sockets. Additionally, the Jetty server hosts a Jersey servlet that provides a RESTful interface to all of that Interesting Stuff (tm).
I'd like to use Spring to inject shared DAOs and application service objects into both the legacy side and into my Jersey resources. This requires that an ApplicationContext be shared between the legacy components and Jersey. It seems that I would need to create the application context, wire it to my legacy components and then pass the application context to the Jersey ServletContext when configuring the embedded Jetty server (which I'm currently doing programatically).
Unfortunately, it's not clear how I can pass an existing application context into the Jersey ServletContext. Can it be done? Is there a better approach?
I'd like to note that this differs from the other Jersey + Jetty + Spring questions I've found on SO, which don't require an application context to be shared outside of Jersey.
I assume that your code starting Jetty is something like:
Server server = new Server(...);
server.setHandler(new WebAppContext(...));
You can get the ServletContext from WebAppContext and set the SpringContext on it:
WebAppContext wac = new WebAppContext(...);
ServletContext sc = wac.getServletContext();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, springContext);

Resources