无法打开 ServletContext 资源 [/WEB

编程入门 行业动态 更新时间:2024-10-27 20:35:02
本文介绍了无法打开 ServletContext 资源 [/WEB-INF/applicationContext.xml]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的,我是问这个问题的第 500 个用户,我阅读了很多答案 但仍然没有运气.

Ok, I am 500th user asking this question, I read many answers but still having no luck.

父模块 pom 包含:

parent module pom contains:

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.framework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.framework.version}</version> </dependency>

子模块有 maven-jetty-plugin,我用 jetty:run 运行我的 webapp 模块.

Child module has maven-jetty-plugin and I run my webapp module with jetty:run.

web.xml 定义了标准的调度模块:

web.xml defines standard dispatcher module:

<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>

我在 WEB-INF 下有文件 dispatcher-servlet.xml,但启动失败:

I have file dispatcher-servlet.xml under WEB-INF, though start fails with:

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

怎么了?文档和大家都说Spring MVC会搜索XX-servlet.xml,其中XX是servlet的名字.为什么要搜索applicationContext.xml?

What is wrong? Documentation and everybody says that Spring MVC will search for XX-servlet.xml, where XX is name of servlet. Why does it search for applicationContext.xml?

推荐答案

ContextLoaderListener 有自己的上下文,所有 servlet 和过滤器都共享该上下文.默认情况下它会搜索 /WEB-INF/applicationContext.xml

ContextLoaderListener has its own context which is shared by all servlets and filters. By default it will search /WEB-INF/applicationContext.xml

您可以使用此自定义

<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/somewhere-else/root-context.xml</param-value> </context-param>

在 web.xml 上,或者如果你不需要的话,删除这个监听器.

on web.xml, or remove this listener if you don't need one.

更多推荐

无法打开 ServletContext 资源 [/WEB

本文发布于:2023-10-28 17:44:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法打开   资源   ServletContext   WEB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!