Spring

2 respostas
G

To começando com o spring, primeiro exemplo e não tem jeito de fzer rodar :(

tenho uma interface
public interface GreetingService {

    void syGreeting();
}
a implementação
public class GreetingServiceImpl implements GreetingService{
private String greeting;
public GreetingServiceImpl(){

}
public GreetingServiceImpl(String greeting){
    this.greeting = greeting;
}

    public void syGreeting() {
        System.out.println(greeting);
    }
    public void setGreeting(String greeting){
        this.greeting = greeting;
    }

}
o xml (o vilao da historia :evil: )...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="greetingService" class="com.springificacao.hello.GreetingServiceImpl">
        <property name="greeting" value="Buenos Dias!"/>
    </bean>
</beans>
e executo com essa classe..
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){
        BeanFactory factory = new XmlBeanFactory( 
                new FileSystemResource("hello.xml"));

        GreetingService greetings = (GreetingService) factory.getBean("greetingService");
        greetings.syGreeting();
    }
}

ganho o seguinte erro :

org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
......
 nested exception is org.xml.sax.SAXParseException: Element type "beans:beans" must be declared.

ja tentei d tudo, ja "googliei" e, tb "gujei" e nada de obter uma resposta...

2 Respostas

A

Os schemas de XML devem ser definidos no início do arquivo.

<?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" default-autowire="no">

G

ja tinha feito isso, mas o erro persiste …

alguem tem alguma sujestão ?

Criado 2 de fevereiro de 2009
Ultima resposta 2 de fev. de 2009
Respostas 2
Participantes 2