Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring class path resource [applicationContext.xml] cannot be opened because it does not exist

Tags:

java

spring

xml

I'm placing applicationContext.xml in the same directory and package as my Java classes.

Doing the following to read it:

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

Yet I am consistently met with:

IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException

Which I do not get: The file is there, in the same directory as the classes. They're even compiled to /out and I can see it's all there.

I've tried putting it in src/resources/applicationContext.xml but to no avail.

like image 639
cbll Avatar asked Dec 18 '25 20:12

cbll


1 Answers

Spring will look for it in the root of the classpath ...

  • The "same directory and package as my Java classes" is not at the root of your classpath
  • src/resources is not on your classpath at all

If you put it in src/main/resources then it will be (1) on your classpath and (2) in the root of your classpath.

like image 143
glytching Avatar answered Dec 21 '25 09:12

glytching