RSS

Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened

19 Oct

Hi folks,

When executing the simple Spring application using the eclipse IDE getting the below Exception

“Nested exception is java.io.FileNotFound  Exception: class path resource [applicationContext.xml] cannot be opened because it does not exist”

To create the spring application, just follow the steps mentioned in the below site

http://www.javatpoint.com/example-of-spring-application-in-eclipse

After successfully completed all the steps, when try to execute the applicataion will see the below exception

log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
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
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
 at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
 at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
 at com.spring.Test.main(Test.java:30)

Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
 at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:141)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
 … 4 more

Here is the solution to execute the above application successfully with out any issue

Provide the absolute path (including the package path) to the applicationContext.xml file like below

Resource resource=new ClassPathResource(“com/spring/applicationContext.xml”); 

Here is the complete Test.java files

public class Test {
public static void main(String[] args) {
          Resource resource=new ClassPathResource(“com/spring/applicationContext.xml”);
BeanFactory factory=new XmlBeanFactory(resource);
Student student=(Student)factory.getBean(“studentbean”);
student.displayInfo();
}
}

After making the above modification and execute the application. Will see the below output

Output

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Hello: Vimal Jaiswal

Happy coding!.

Get glued to know more updates.

Have a nice day

Advertisements
 
1 Comment

Posted by on October 19, 2014 in Uncategorized

 

One response to “Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened

  1. swati

    February 6, 2015 at 5:21 am

    u need to add commons jar
    — ex–\Apache\Commons\commons-logging.jar

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: