What is the difference between ApplicationContext and WebApplicationContext in Spring MVC?

前端 未结 5 732
迷失自我
迷失自我 2020-11-22 06:53

What is the difference between Application Context and Web Application Context?

I am aware that WebApplicationContext is used for Spring MVC architectur

5条回答
  •  攒了一身酷
    2020-11-22 07:25

    Going back to Servlet days, web.xml can have only one , so only one context object gets created when server loads an application and the data in that context is shared among all resources (Ex: Servlets and JSPs). It is same as having Database driver name in the context, which will not change. In similar way, when we declare contextConfigLocation param in Spring creates one Application Context object.

     
          contextConfigLocation
          com.myApp.ApplicationContext
     
    

    You can have multiple Servlets in an application. For example you might want to handle /secure/* requests in one way and /non-seucre/* in other way. For each of these Servlets you can have a context object, which is a WebApplicationContext.

    
        SecureSpringDispatcher
        org.springframework.web.servlet.DispatcherServlet
        
            contextClass
            com.myapp.secure.SecureContext
        
    
    
        SecureSpringDispatcher
        /secure/*
    
    
        NonSecureSpringDispatcher
        org.springframework.web.servlet.DispatcherServlet
        
            contextClass
            com.myapp.non-secure.NonSecureContext
        
    
    
        NonSecureSpringDispatcher
        /non-secure/*
    
    

提交回复
热议问题