Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java EE (J2EE) и Spring > spring hello world - not working :(


Автор: Crocodile 13.9.2007, 13:05
Использую 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. Непредставляю что ето за ошибки.

Автор: Zamuta 13.9.2007, 13:54
Crocodile, добавь в свой проект библиотеку commons-logging-xxx.jar. Брать http://commons.apache.org/logging/.

Автор: Crocodile 13.9.2007, 14:00
Спасиба. Решено.

Автор: Tony 13.9.2007, 22:46
Скоро будут появляться вопросы типа: "4то такое javac ?" smile  Извините меня за off topic.  smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)