Hello everybody. I am writing "hello world" in Java using Spring. So what I did.
1) The Eclipse EE Indigo has created a new Java Project.
2) I downloaded spring-framework-3.1.1.RELEASE unpacked into a directory. Have the files in the directory dist (there are many, for some reason I thought that I needed to take a "spring.jar") from org.springframework.aop-sources-3.1.1.RELEASE.jar ending org.springframework.web-sources -3.1.1.RELEASE.jar
3) I created the four files. The first is the xml
Second class with void mainCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="greetingService" class="ua.maybe"> <property name="greeting" value=" VIZA!" /> </bean> </beans>
Made another classCode:package ua; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource; public class Full { /** * @param args */ public static void main(String[] args) { //maybe m=new maybe(); //AbstractApplicationContext ctx=FileSystemApplicationText; BeanFactory factory = new XmlBeanFactory(new FileSystemResource("da.xml")); Maybe greetingService = (Maybe) factory.getBean("greetingService"); greetingService.sayGreeting(); } }
And the end made interfaceCode:package ua; public class Maybe implements Gast { private String greeting; Maybe(){} public void sayGreeting() { System.out.println("Hello Spring! "+greeting); } public void setGreeting(String greeting) { this.greeting = greeting; } }
After that, compile the project and get the error. Why is it so?Code:package ua; public interface Gast { void sayGreeting(); }
Code: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:175) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:157) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:168) at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:158) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:77) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:66) at ua.Full.main(Full.java:16) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(Unknown Source) 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


Reply With Quote