java.io.FileNotFoundException:无法打开类路径资源,因为它不存在 [英] java.io.FileNotFoundException: class path resource cannot be opened because it does not exist

查看:1615
本文介绍了java.io.FileNotFoundException:无法打开类路径资源,因为它不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的项目设置配置位置,但我不断收到以下错误消息:

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆