一个web工程自动加载的配置文件只有web.xml,想要加载其他.xml必须在web.xml里面进行配置。
用spring的时候需要一个bean容器来管理所有的bean,所有bean默认是写在applicationContext.xml里的,在web.xml里面是这么设置的,
方式一:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dispatcherServlet-servlet.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>是可选项,如果没有的话就加载applicationContext.xml,也可以用它指定其他配置文件。
方式二:
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
这种没用过。