[英]ClassPathXmlApplicationContext cannot find the xml file
I read several posts regarding this but still don't understand how to solve my issue. 我阅读了几篇与此相关的文章,但仍然不明白如何解决我的问题。 I am creating a Spring Web Service using this source as a starting point: http://eggsylife.co.uk/2010/01/03/spring-3-restful-web-services/
我正在使用此源作为起点来创建Spring Web Service : http : //eggsylife.co.uk/2010/01/03/spring-3-restful-web-services/
It has src/main/java
folders and src/main/webapp/
... 它具有
src/main/java
文件夹和src/main/webapp/
...
I want to add a rest client in com.spring.client/RestClient.java
: 我想在
com.spring.client/RestClient.java
添加一个休息客户端:
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/META-INF/client-context.xml");
RestTemplate restTemplate = (RestTemplate)ctx.getBean("restTemplate");
addStudent(restTemplate);
}
But when I try to run it, it cannot find the client-context.xml
file no matter where I put it. 但是,当我尝试运行它时,无论放置在哪里,它都找不到
client-context.xml
文件。 I'tried "client-context.xml"
, "META-INF/client-context.xml"
, etc... 我尝试了
"client-context.xml"
, "META-INF/client-context.xml"
等。
I've tried putting my client-context.xml
in src/main
, src/main/webapp
, src/main/webapp/META-INF
, src/main/webapp/WEB-INF
, ... 我尝试将我的
client-context.xml
放在src/main
, src/main/webapp
, src/main/webapp/META-INF
, src/main/webapp/WEB-INF
,...
It seems weird. 这看起来很奇怪。 I looked around and found another Spring REST tutorial with a working client.
我环顾四周,发现另一个工作正常的Spring REST教程。 In that project, the
src/main/webapp
folders have a blue "S" on top of it while my other project does it. 在该项目中,
src/main/webapp
文件夹顶部有一个蓝色的“ S”,而我的其他项目也有。 It's just a regular looking folder. 这只是一个普通的文件夹。
Does that make a difference? 这有什么区别吗? How do I fix this error?
我该如何解决这个错误?
Thanks! 谢谢!
src/main/resources/META-INF
. src/main/resources/META-INF
。 The classpath root is WEB-INF/classes
, and src/main/resources
goes there, together with src/main/java
classpath的根是
WEB-INF/classes
, src/main/resources
和src/main/java
一起去
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.