eclipse java.io.FileNotFoundException: 无法打开 ServletContext 资源 [/WEB-INF/final-servlet.xml]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10831185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/final-servlet.xml]
提问by JOHND
I am creating simple maven project plugin . Application directory structure is like standard maven project directory structure.
我正在创建简单的 Maven 项目插件。应用程序目录结构就像标准的 maven 项目目录结构。
I have place application-context.xml file under src/main/java/resources folder.
我将 application-context.xml 文件放在 src/main/java/resources 文件夹下。
Problem :
问题 :
How to configure this path in web.xml file ?
如何在 web.xml 文件中配置此路径?
I am getting java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/final-servlet.xml]
error
我收到 java.io.FileNotFoundException: 无法打开 ServletContext 资源[/WEB-INF/final-servlet.xml]
错误
Do i have to configure my project properties in eclipse???
我必须在 Eclipse 中配置我的项目属性吗???
Can any one guide me on the same....??
任何人都可以指导我....??
Thanks in advance..>!
提前致谢..>!
回答by Dani
Put the final-servlet.xml under WEB-INF folder and it will works. What you are asking about your application-context.xml i think is something like this:
将 final-servlet.xml 放在 WEB-INF 文件夹下,它将起作用。你在问你的 application-context.xml 我认为是这样的:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/final-servlet.xml
classpath:application-context.xml
</param>
</context-param>
回答by Dave Newton
Files in the resources directory are deployed to the classpath, not WEB-INF
. If you want the file in WEB-INF
then it needs to be in src/webapp/WEB-INF
, as in any Maven-based web app project.
资源目录中的文件被部署到类路径,而不是WEB-INF
. 如果您想要该文件,WEB-INF
那么它需要在 中src/webapp/WEB-INF
,就像在任何基于 Maven 的 Web 应用程序项目中一样。
Otherwise the location referenced in the Spring config needs to be classpath-relative.
否则 Spring 配置中引用的位置需要是类路径相关的。
回答by julia
/WEB-INF/final-servlet.xml - in context-param in DispatcherServlet
/WEB-INF/final-servlet.xml - 在 DispatcherServlet 的上下文参数中
and put final-servlet.xml in your_web_app/WEB-INF folder.
并将 final-servlet.xml 放在 your_web_app/WEB-INF 文件夹中。
Should work
应该管用