ApplicationContext and ServletContext

前端 未结 5 576
孤独总比滥情好
孤独总比滥情好 2020-12-23 09:55

I get confused between the two ApplicationContext and ServletContext when it comes to Spring MVC Application. I know that There is just only One ApplicationContext per Sprin

5条回答
  •  甜味超标
    2020-12-23 10:09

    They are separate things. Every Java web applications based on Servlet technology will have a servlet context, whether it's a spring application or not. In contrast, the ApplicationContext is a Spring thing; in very simple terms, it's a container to hold Spring beans.

    To initiate the value for both ApplicationContext and ServletContext, in web.xml, we will add something in context-param tag.

    It would help if you quote an example for this, because, as far as I know, context-param is used for ServletContext, and not ApplicationContext.

    Update:

    You can use a context-param to provide the locations of the root application context configuration files, as below.

    
        contextConfigLocation
        
            /WEB-INF/root-context.xml
            /WEB-INF/applicationContext-security.xml
        
    
    

提交回复
热议问题