无法打开ServletContext资源[/WEB

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

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

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

父模块pom包含:

<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运行我的webapp模块:运行。

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>

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

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

您可以使用

You can customize this by using

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

发布评论

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

>www.elefans.com

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