解决SpringMVC系统启动时,地址映射两次问题

由于在系统初始化期间,启动了ContextLoaderListener,原有配置如下
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext*.xml</param-value> 
</context-param>
 
由于SpringMVC的配置文件与spring的其他文件名基本一致导致系统初始化期间先被扫描一遍,也就是启动了一遍,此时我们又在web.xml中配置:
<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:springmvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
 
就意味着ContextLoaderListener加载了一遍,DispatcherServlet又加载了一遍,因为做法很简单,将SpringMVC的配置文件改成其他文件名即可。
posted @ 2015-12-20 13:33  Mr.Peng Sir  阅读(252)  评论(0编辑  收藏  举报