我正在尝试为我的项目设置配置位置,但我不断收到以下错误:
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
下的资源也是如此:它们最终位于类路径的根目录下。
所以资源的路径是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/