java.io.FileNotFoundException:无法打开类路径资源,因为它不存在 [英] java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
问题描述
我正在尝试为我的项目设置配置位置,但我不断收到以下错误消息:
I am trying to set the configuration location for my Project but I keep getting the following error:
java.io.FileNotFoundException:类路径资源 [main/resources/app-context.xml]无法打开,因为它没有打开 存在
java.io.FileNotFoundException: class path resource [main/resources/app-context.xml] cannot be opened because it does not exist
我的项目设置如下:
我的代码设置为:
ApplicationContext context = new ClassPathXmlApplicationContext(configLocation: "main/resources/app-context.xml");
我该如何解决?
推荐答案
直接放在src/main/java
下的内容位于默认包中,位于类路径的根目录下. src/main/resources
下的资源是相同的:它们最终位于类路径的根.
What you put directly under src/main/java
is in the default package, at the root of the classpath. It's the same for resources put under src/main/resources
: they end up at the root of the classpath.
因此资源的路径是app-context.xml
,而不是main/resources/app-context.xml
.
So the path of the resource is app-context.xml
, not main/resources/app-context.xml
.
这篇关于java.io.FileNotFoundException:无法打开类路径资源,因为它不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!