Saw same issues in others queries, but did not find the answer, hence posting it afresh.

Created a sample Helloworld service in Rest and deployed it in Tomcat-Jersey. Not using Maven. Injecting a spring bean define in applicationContext.xml which is present in WEB-INF directory.

Deployed the service in Tomcat within Eclipse. But when I execute the rest service, cannot find file applicationContext.xml. Once I copy the file to WEB-INF/classes only, it works.

What is the way to make it work by keeping it only in WEB-INF?

web.xml :


Rest service code snippet :

    ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

No correct solution


It seems reasonable to work when you drop the context descriptor under /WEB-INF/classes because this location is the root of classpath.

So try loading with below uri (without prefix) if you want to drop your applicationContext.xml under WEB-INF folder:

    ctx = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext.xml");

Otherwise, can you explain why are you trying to load your applicationContext.xml within your web application?

Alternatively, you can load your application context programatically as follows:

ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());


If you are using Intellj IDEA and having problem with ApplicationContext.xml path; Go to File and click Project Structure. Under the Project Settings, click Facets, at the Web Section you will see Web Resource Directories. You should define Web Resource Directory to your /WEB-INF folder. If your /WEB-INF folder is in the subpath like below;


Then choose /web directory to cover all your files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top