File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Configuration Issues with Spring Framework on eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Configuration Issues with Spring Framework on eclipse" Watch "Configuration Issues with Spring Framework on eclipse" New topic
Author

Configuration Issues with Spring Framework on eclipse

Ak Rahul
Greenhorn

Joined: Jul 08, 2009
Posts: 21
Hi everyone,
I am new to Spring Frameworks and am using eclipse IDE to run it. I tried a simple program....which seems to be giving some runtime exceptions when I run it. I shall be really grateful if someone can help me with this.

The config.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean id = "firstbean"
class = "InjectionBean"
p:name = "andy"
p:roll = "2121"
p:dept = "Engg"
p:college = "BU"/>

</beans>

My InjectionBean.java is as follows:
public class InjectionBean {
private String name, roll, dept, college;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getRoll() {
return roll;
}

public void setRoll(String roll) {
this.roll = roll;
}

public String getDept() {
return dept;
}

public void setDept(String dept) {
this.dept = dept;
}

public String getCollege() {
return college;
}

public void setCollege(String college) {
this.college = college;
}

@Override
public String toString() {
return "InjectionBean [college=" + college + ", dept=" + dept + ", name="
+ name + ", roll=" + roll + ", toString()=" + super.toString()
+ "]";
}

}


And I have a main class(Main.java) that runs this app.

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;


public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
XmlBeanFactory beanXml = new XmlBeanFactory(new ClassPathResource("config.xml"));
InjectionBean firstBean = (InjectionBean) beanXml.getBean("firstbean");
System.out.println(firstBean);
}

}


When I am running the main class.....as a java application...I am getting the following error/exception.

Jul 8, 2009 6:35:47 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [config.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [config.xml]; nested exception is java.io.FileNotFoundException: class path resource [config.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 Main.main(Main.java:12)
Caused by: java.io.FileNotFoundException: class path resource [config.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
... 4 more

I have the commons-logging-1.0.1.jar and spring.jar included in my eclipse project. Any response to get rid of this exception shall be highly appreciated.

regards,
Rahul
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

config.xml is not in your classpath. In Eclipse's Run configuration window, go to the Classpath tab, select User entry, and add the folder where config.xml is in.


[My Blog]
All roads lead to JavaRanch
Ak Rahul
Greenhorn

Joined: Jul 08, 2009
Posts: 21
Thanks Christophe. It works fine now. I really appreciate your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuration Issues with Spring Framework on eclipse
 
Similar Threads
xml bean injection - error - netbeans 6.5
spring inside eclipse
Spring: Hello World Does Not Work
using ClassPathXmlApplicationContext to load beans
class path resource [spring xml file] cannot be opened