spring的applicationContext.xml如何自动加载
web工程自动加载的配置文件只有web.xml,想加载其他文件需要在web配置文件配置
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>
是可选项,如果没有的话就加载applicationContext.xml,也可以用它指定其他配置文件。
<context-param>
2 <param-name>contextConfigLocation</param-name>
3 <param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value>
4 </context-param>