[英]ClassPathXmlApplicationContext cannot find the xml file
我阅读了几篇与此相关的文章,但仍然不明白如何解决我的问题。 我正在使用此源作为起点来创建Spring Web Service : http : //eggsylife.co.uk/2010/01/03/spring-3-restful-web-services/
它具有src/main/java
文件夹和src/main/webapp/
...
我想在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);
}
但是,当我尝试运行它时,无论放置在哪里,它都找不到client-context.xml
文件。 我尝试了"client-context.xml"
, "META-INF/client-context.xml"
等。
我尝试将我的client-context.xml
放在src/main
, src/main/webapp
, src/main/webapp/META-INF
, src/main/webapp/WEB-INF
,...
这看起来很奇怪。 我环顾四周,发现另一个工作正常的Spring REST教程。 在该项目中, src/main/webapp
文件夹顶部有一个蓝色的“ S”,而我的其他项目也有。 这只是一个普通的文件夹。
这有什么区别吗? 我该如何解决这个错误?
谢谢!
src/main/resources/META-INF
。 classpath的根是WEB-INF/classes
, src/main/resources
和src/main/java
一起去
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.