• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuration Issues with Spring Framework on eclipse

 
Ak Rahul
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ak Rahul
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe. It works fine now. I really appreciate your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic