方法如下
1.导入相应的maven坐标
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
2.创建spring核心配置文件:applicationContext.xml
3.在web.xml中配置监听器:ContextLoaderListener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
该监听器帮忙加载配置文件,创建spring
容器需要给初始化参数
4.配置全局初始化参数
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
classpath:即类加载路径下的配置文件,maven项目结构中的resources包下
5.手动的将maven引入的坐标配置到web中
方法如下