在web.xml文件中配置
第一种(默认)
<!--监听web容器的启动,加载spring的配置文件,默认文件名称为applicationContext.xml,在WEB-INF目录下-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
第二种(指定spring配置文件)
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<!--maven项目将配置文件放在resources目录下-->
<param-value>classpath:applicationContext.xml</param-value>
</context-param>