简体   繁体   中英

Difference between root and web applicationContext spring mvc

I am new spring mvc and trying to understand some basics. Some of the things are clear to me but still I have some doubts regarding spring basics.

First of all let me put things that are clear to me.(If I am wrong please object me).

There are two kinds of xml files in spring mvc : rootApplicationContext.xml and webApplicationContext.xml

context-param tag in web.xml defines rootApplicationContext.xml and servlet tag having DispatcherServlet (acting as a form controller) defines the webApplicationContext.xml parameters, and beans of rootApplicationContext are eccessible in all webApplicationContext.xml files

features that are required in all parts of application like hibernate and DAO configurations are written in rootApplicationContext

Now here are my questions :

(1)I think rootApplicationContext is loaded at application loading time and webApplicationContext is loaded when DispatcherServlet class is loaded. So when does the DispatcherServlet class is loaded ?

(2)when the objects of controller-action are created, at application loading time or at the calling time ?

(3)Which type of objects created for controller-action , singleton or prototype ?

(3)Which xml should contain the bean definations of filter , interceptor , AOP classes and why ?

For some of my doubts are reffered spring documentation but the still I have some doubts.

Thanks

You are right in all points, and that's a very good start. All servlets are either loaded on container startup (if you specify a load-on-startup value in web.xml) or whenever the container feels like it otherwise, but it's usually not something you have to worry about. Singletons are loaded on the start, prototypes, obviously, when needed. Most objects are singletons, and should thus be stateless. It is a good idea to maintain state only where you know you can. You define beans in the context they will be used. Interceptors are used in the web context only, so that's where you put them. Same logic applies to everything else, but be mindful of web-related classes used outside of Spring MVC, like your own filters and similar. Only requests that have actually hit DispatcherServlet will be aware of Spring MVC stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM