gpt4 book ai didi

java - Intellij 下找不到 *.xml 文件

转载 作者:行者123 更新时间:2023-12-01 19:35:23 26 4
gpt4 key购买 nike

我正在尝试运行一些需要在 Intellij 下读取 spring xml 配置的单元测试用例,但 Intellij 失败并出现以下错误。

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [test.xml]; nested exception is java.io.FileNotFoundException: class path resource [test.xml] cannot be opened because it does not exist

在Intellij下,我的文件夹结构是:

src/main/java
src/main/test
src/main/spring

text.xml 文件位于 src/main/spring 下

加载配置文件的相关java代码为:

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("test.xml")

我搜索了几篇帖子,并尝试了以下方法:

1) marked src/main/spring folder as "sources" or "resources".
2) added src/main/spring as a module under project structure.

但不幸的是,它们都不起作用。

我在 build.gradle 设置中的 sourceSet 是:

sourceSets {
main {
java {
srcDir 'src/main/java'
}
proto {
// In addition to the default "src/main/proto"
srcDir "src/main/proto"
}
}

test {
java {
srcDir 'src/main/test'
}

proto {
srcDir "src/main/proto"
}
}
}

我是 Gradle 的新手,希望有人能给我提示。真的很感激!

最佳答案

您需要将src/main/spring添加到build.gradle文件中的resources中,参见related answer .

sourceSets {
main {
java {
srcDir 'src/main/java'
}
...
resources {
srcDir 'src/main/spring'
}
...
}
}

关于java - Intellij 下找不到 *.xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57896042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com