Thursday, January 29, 2009

Hello World Spring Program does not work

Hi,

If you just started to learn spring framework with the traditional approach by writing a helloworld program, then you might come across this:

BeanFactory factory; factory = new XmlBeanFactory(new InputStreamResource(new FileInputStream("hello.xml")));

here it shows the following error after run:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.beans.factory.support.Abstract BeanFactory.(AbstractBeanFactory.java:99)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.(AbstractAutowire CapableBeanFactory.java:97)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.(AbstractAutowire CapableBeanFactory.java:106)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.(DefaultListableBeanFacto ry.java:87)
at org.springframework.beans.factory.xml.XmlBeanFacto ry.(XmlBeanFactory.java:67)
at org.springframework.beans.factory.xml.XmlBeanFacto ry.(XmlBeanFactory.java:56)
at HelloApp.main(HelloApp.java:25)


This happens if you don't have commons-logging.jar in your classpath. You can download commons-logging.jar library from

http://commons.apache.org/downloads/download_logging.cgi