【Spring学习笔记】Spring中Application Context和Servlet Context的区别

1. Servlet Context

It is initilized when an servlet application is deployed. Servlet Context holds all the configurations (init-prarm, context-params etc) of the of the whole servlet application.

2. Application Context

Is is a spring thing. It is initilized by Spring. It holds all the bean defination and life-cycle of the of the beans that is defined inside the spring configuraion files. Servlet-Context has no idea about this things.

There are two types of context in spring parent and child.

Spring Parent Context (Application Context / Root Context )

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/service-context.xml,
            /WEB-INF/dao-context.xml,
            /WEB-INF/was-context.xml,
            /WEB-INF/jndi-context.xml,
            /WEB-INF/json-context.xml
        </param-value>
 </context-param>

When spring container start ups it reads all the bean definitions from the configuration files and creates beans objects and manages life cycle of the beans objects. This configuartion is totally optionl.

Spring Child Context ( WebApplicationContext / Child Context )

<servlet>
    <servlet-name>myWebApplication</servlet-name>
    <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jobbuzz-web</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

when spring web application starts it will look for spring bean configration file myWebApplication-servlet.xml. It will read all the bean definations and create and manages the bean objects life cycle. If parent spring context is available it will merge the child spring context with the parent spring context. If there is not spring parent context the application will have only child spring context.

References:
1. ApplicationContext and ServletContext

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值