**前言:**创建一个web项目,首先从web.xml开始,是web应用的入口。其中的核心配置文件有哪些呢
contextConfigLocation
contextConfigLocation 用来配置自定义的配置文件的加载路径。比如在SSM项目中会有spring,spirngMVC的xml文件。而为了便于管理和阅读,会将各自相关的bean配置在单独的xml中,所以会用contextConfigLocation去统一加载。用法如下:
```java
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/spring-*.xml</param-value>
</cntext-param>
其中classpath和classpath的区别是:
classpath: 只会到你的class路径去查找文件
classpath:不仅包含class路径,还包括jar文件中(class路径)进行查找。
如果项目有多个classpath路径,并同时加载多个classpath路径下的文件,就应该使用classpath*
ContextLoaderListener
ContextLoadListener是一个监听器。它负责监听Web项目的启动过程,ContextLoaderListener中定义了两个方法: contextInitialized和contextDestroyed,contextInitialized执行时,会初始化web应用的根上下文信息。
对于Spring承载的web应用而言,可以在指定在web应用程序启动时载入IOC容器(或者称为WebApplicationContext)。这个功能
是由ContextLoaderListener这个监听器类来完成的。ContextLoaderListener继承自ContextLoader,实际上就是通过ContextLoader
来完成IOC的初始化的。ContextLoaderListener可以看做是Spring的启动器,Spring从这里开始。在web.xml中配置如下
<listener>