oky_sabeni
oky_sabeni

Reputation: 7822

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!

Upvotes: 2

Views: 20784

Answers (1)

Bozho
Bozho

Reputation: 597382

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

Upvotes: 7

Related Questions