• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with XMLBeanFactory

 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

When I am writing following code in Eclipse the XMLBeanFactory class show in strike and it also says javadoc not available. I include all jar files required for XmlBeanFactory like "spring-beans-2.5.6.jar". But problem is still same it produce following exception
-------------------------
Error/Exception

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:83)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.<init>(FactoryBeanRegistrySupport.java:43)
at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:176)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:155)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:166)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:156)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:77)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:66)
at net.roseindia.TestRunSpring.main(TestRunSpring.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more

--------------------------
Three files code here and I am running TestRunSpring.java as application

Code 1 is here TestRunSpring.java
package net.roseindia;


import java.util.Map;

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

import org.springframework.util.Assert;


@SuppressWarnings("deprecation")
public class TestRunSpring {

/**
* @param args
*/

@SuppressWarnings("deprecation")
public static void main(String[] args) {
// TODO Auto-generated method stub
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(

"SpringHelloWorld.xml"));

TestSpring1 myBean = (TestSpring1) beanFactory

.getBean("Spring3HelloWorldBean");

myBean.sayHello();



}

}

code 2 is here TestSpring1.java

package net.roseindia;

public class TestSpring1 {

/**
* @param args
*/

public void sayHello(){

System.out.println("Hello Spring 3.0");

}

}

code 3 TestSpringHello.xml

<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="TestSpring1"
class="net.roseindia.TestSpring1" />

</beans>

Please help
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have commons-logging.jar inside WEB-INF/lib of your application..
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. But I am facing a new problem and XmlBeanFactory still remains the same.

Exception in thread "main" java.lang.ExceptionInInitializerError
at net.roseindia.TestRunSpring.main(TestRunSpring.java:25)
Caused by: java.lang.NullPointerException
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:104)
... 1 more

Please help
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please post your full exception trace and edit your topic, to include code tags..
EDIT: where is Spring3HelloWorldBean defined in the xml file, I can't see it.. I guess, you have not defined this bean, so a NPE is coming..
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, In the class you are loading SpringHelloWorld.xml, but i can see only TestSpringHello.xml , can you post SpringHelloWorld.xml also, and where is the SpringHelloWorld.xml file kept?
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the screen shot of class as attached:

The OUTPUT is correct but Exception is also occuring please find out and exception as below: The red one is out put which is correct

Mar 10, 2011 3:45:04 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [SpringHelloWorld.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [SpringHelloWorld.xml]; nested exception is java.io.FileNotFoundException: class path resource [SpringHelloWorld.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 net.roseindia.TestRunSpring.main(TestRunSpring.java:25)
Caused by: java.io.FileNotFoundException: class path resource [SpringHelloWorld.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
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav x Jain wrote:Please find the screen shot of class as attached:
Caused by: java.io.FileNotFoundException: class path resource [SpringHelloWorld.xml] cannot be opened because it does not exist


The above line clearly tells that the file cannot be found.. that means the file is not on classpath.. where have you kept SpringHelloWorld.xml?
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad Thank you for helping me a lot. Please tell me one more thing how SpringHelloWorld.xml created I didn't use
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error Resolved Thank you very much....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic