美文网首页征服Spring
Spring环境下的几个xml文件

Spring环境下的几个xml文件

作者: 沐兮_d64c | 来源:发表于2018-04-25 19:29 被阅读6次

1,applicationContext.xml

1)定义web根应用环境下的bean对象。eg:spring全局配置文件,如redis配置,elasticsearch配置等
The applicationContext.xml defines the beans for the "root webapp context".

2,dispatcher-servlet.xml

1) 定义Servlet上下文的bean。eg:mvc里面的,视图解析、静态资源处理、控制器、拦截器等配置。
defines the beans for one servlet's app context.
2)如果没有配置contextConfigLocation ,Spring默认加载配置文件为/WEB-INF/[servlet名字]-servlet.xml来初始化DispatcherServlet。参考XmlWebApplicationContext

image.png

3,applicationContext、dispatcher-servlet.xml对比

1)根元素都是<beans>,两者也同样都可以托管java bean。
2)applicationContext.xml定义跟应用上下文root webapp context;dispatcher-servlet.xml定义的是一个servlet应用的上下文(webapp上下文中可能还有redis,mysql等上下文等,可以使用import导入)。

image.png image.png
3)ApplicationContext初始化在前,dispatcher-servlet初始化在后。dispatcher-servlet可以引用ApplicationContext中的bean,反之不行。
Beans in dispatcher-servlet.xml can reference beans in applicationContext.xml, but not vice versa.
4)都需要在web.xml中进行配置
image.png image.png

4,web.xml

Web Module Deployment Descriptor Web模块部署描述符。

1)每个web.xml文件的根元素为<web-app>
2)<welcome-file-list>指定欢迎界面
3)配置<servlet> 和 <servlet-mapping>
4)配置根应用的启动参数<context-param>,配置servlet的初始化参数<init-param>
5)配置<filter>和<filter-mapping> eg:shiroFilter
6)配置监听器eg:ContextLoaderListener

5,其他

1)dispatcher-servlet.xml中配置拦截器。<mvc:interceptor>
2)web.xml中配置过滤器。<filter>
3)web.xml中配置监听器。<listener>

相关文章

网友评论

    本文标题:Spring环境下的几个xml文件

    本文链接:https://www.haomeiwen.com/subject/dvgylftx.html