java.io.FileNotFoundException : class path resource cannot be opened because it does not exist 错误

标签 java spring file intellij-14

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

java.io.FileNotFoundException: class path resource [main/resources/app-context.xml] cannot be opened because it does not exist

我的项目是这样设置的:

enter image description here

我的代码设置为:

ApplicationContext context = new ClassPathXmlApplicationContext(configLocation: "main/resources/app-context.xml");

我该如何解决这个问题?

最佳答案

你直接放在 src/main/java 下的是默认包,在类路径的根目录下。放在 src/main/resources 下的资源也是如此:它们最终位于类路径的根目录下。

所以资源的路径是app-context.xml,而不是main/resources/app-context.xml

关于java.io.FileNotFoundException : class path resource cannot be opened because it does not exist 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42863382/

相关文章:

java - IntelliJ : Refactor package causes Guice class-not-found

java - 使用 Betamax 时为 "Illegal use of nonvirtual function call"

java - 拒绝非数字字符

c - 尝试在 C、Linux 中递归打印所有小于特定大小的文件

java - 尝试将文件从一个位置复制到另一个位置

java - 如何配置 Jetspeed 用户密码验证

java - 限制所有类的 Jackson 序列化/反序列化深度

java - Spring :为什么在单元测试中加载应用程序上下文时需要添加javax.el-api依赖项?

python - 有没有办法使用 Python 检索文件名?

mysql - 我无法读取mysql二进制日志