Fernando Loza
Fernando Loza

Reputation: 9

applicationContext.xml doesn't exist for my Spring application

I'm new to Spring, and I am actually reading the book Spring in Practice by Willie Wheeler. I'm trying to run an example from the first chapter.

abr 24, 2014 11:11:55 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c01e99: startup date [Thu Apr 24 11:11:55 CST 2014]; root of context hierarchy
abr 24, 2014 11:11:56 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

What can I do to fix this error?

Upvotes: 0

Views: 850

Answers (1)

Nathan Hughes
Nathan Hughes

Reputation: 96385

Check where you put the applicationContext.xml. The error says that Spring is expecting to find it in the classpath (in the same directories as your class files), but it is not there. For instance, if this example is in a web application, the file should be in (your app)/WEB-INF/classes.

If you are using maven for this, make sure the application context is under src/main/resources. Maven will handle copying it into your classpath.

This might be an IDE problem where you're relying on the IDE to copy the file over from your source directory (with the java files) to the target directory (where the class files get written). To check this in Eclipse you'd right click on your project and look for the menu Build Path -> Configure Build Path, then click on the Source tab to see what target directories are defined for your source folders.

Upvotes: 4

Related Questions