Thursday, May 24, 2012

Resolve Error "org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [Beans.xml]"

Spring projects will compile without any warnings and errors.But when you run the code you will see the exception.

 Reason:  It is the issue with the location of the Beans.xml.So server could not find the  location of the Spring beans xml.
Stacktrace :org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
    at com.mySpringExample.helloExample.HelloClient.main(HelloClient.java:20)
Caused by: java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:143)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
    ... 4 more

Resolution :  
1) Move the spring Beans.xml to the src folder from the current folder. 
Clean and run the project.
See the screen shots below.

Wrong location(Example)

















Right location  

No comments:

Post a Comment

Resolve "Target runtime Apache Tomcat v6.0 is not defined." error

Go to window ->preferences ->Server->Runtime environments . add server Apache Tomcat v6.0 Mention the directory where apache-toma...