Maven项目配置spring时 出现Could not open ServletContext resource [/WEB-INF/applicationContext.xml]解决方案

出现问题的原因

配置Maven项目,我把spring相关的xml都放到了resources下,但是spring默认会去web-inf下寻找xml,所以才会出现错误

Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

解决方法

在web.xml里指定spring相关xml的加载

正确的web.xml里spring加载设置

<context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath:applicationContext.xml</param-value>  
</context-param>
<listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
</listener>  
<servlet>  
        <servlet-name>springMvc</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath:applicationContext.xml</param-value>  
        </init-param>  
        <load-on-startup>1</load-on-startup>  
</servlet>  
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容