简体   繁体   中英

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/

It has src/main/java folders and src/main/webapp/ ...

I want to add a rest client in 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. I'tried "client-context.xml" , "META-INF/client-context.xml" , etc...

I've tried putting my client-context.xml in 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. In that project, the src/main/webapp folders have a blue "S" on top of it while my other project does it. It's just a regular looking folder.

Does that make a difference? How do I fix this error?

Thanks!

src/main/resources/META-INF . The classpath root is WEB-INF/classes , and src/main/resources goes there, together with src/main/java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM