Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileNotFoundException..Classpath resource not found in spring?

Tags:

spring

I have code like this in Main.java :

AbstractApplicationContext context  = new ClassPathXmlApplicationContext("spring-config.xml");

Until recently it was working, but I don't know why it started failing with the below exception:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-config.xml] cannot be opened because it does not exist

the spring-config.xml is in src/main/resources folder.

Actually I wanted to learn about the annotations: @Postconstruct and @Predestroy, so I changed the build path to Jdk 1.6 from Jdk 1.5.

Since then the problem started...

Any clue why it is not working?

NOTE: If any wants to see my project structure please follow this link http://code.google.com/p/javapracticeram/source/browse/trunk/SpringExample/

EDIT: alt text

like image 256
javanoob Avatar asked Aug 08 '10 04:08

javanoob


People also ask

What is classpath resource in spring?

ClassPathResource is a Resource implementation for class path resources. It supports resolution as java. io. File if the class path resource resides in the file system, but not for resources in a JAR.

Is resources folder included in JAR?

Introduction. When you build a java project and pack it into a jar (or a war), the files under the resources folder are included into the jar.

What is default classpath in spring boot?

By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath.


1 Answers

Looking at your classpath you exclude src/main/resources and src/test/resources:

    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>

Is there a reason for it? Try not to exclude a classpath to spring-config.xml :)

like image 177
tolitius Avatar answered Oct 11 '22 13:10

tolitius