Использую Eclipse. Все файлы размещаю в одной и тойже дириктории. В Eclipse добавил external jar file: spring.jar. Eclipse находит все классы Spring. В Eclipse файл HelloApp.java запускаю так: Run As Java Application. Получаю ошибку.
| Код | public interface GreetingService { void sayGreeting(); }
|
| Код | public class GreetingServiceIml implements GreetingService { private String greeting; public GreetingServiceIml() { } public GreetingServiceIml(String greeting) { this.greeting = greeting; } @Override public void sayGreeting() { System.out.println(greeting); } public void setGreeting(String greeting) { this.greeting = greeting; } }
|
| Код | import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource;
public class HelloApp { public static void main(String[] args) throws Exception { BeanFactory factory = new XmlBeanFactory(new FileSystemResource("hello.xml")); GreetingService greetingService = (GreetingService) factory.getBean("greetingService"); greetingService.sayGreeting(); } }
|
hello.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="greetingService" class="GreetingServiceImpl"> <property name="greeting" value="@lio6ka" /> </bean> </beans>
|
| Код | Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:79) at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:142) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:132) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:143) at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:99) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:72) at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61) at HelloApp.main(HelloApp.java:7)
|
Я первый день с Spring. Непредставляю что ето за ошибки. |