Aprendendo Spring

0 respostas
gcobr

Comecei ontem meus estudos sobre o framework Spring e já estou enfrentando um problema nos primeiros testes.

Quero construir XmlBeanFactory e para isso uso:

InputStream is = Teste.class.getClassLoader().getResourceAsStream("beans.xml");
BeanFactory factory = new XmlBeanFactory(is);

O arquivo beans.xml contém todos os tags necessários:

<bean id="myFirstBean" class="beans.MyFirstBean">
	<property name="secondBeanReference"><ref bean="mySecondBean"/></property>
    <property name="thirdsBeanReference"><ref bean="myThirdBean"/></property>
    <property name="sillyStringProp">My First Bean</property>
</bean>

<bean id="mySecondBean" class="beans.MySecondBean">	
	<property name="sillyStringProp">My Second Bean</property>
</bean>

<bean id="myThirdBean" class="beans.MyThirdBean">
	<property name="sillyStringProp">My Third Bean</property>
</bean>

Mas surge a seguinte excessão:

org.springframework.beans.factory.BeanDefinitionStoreException: Line 1 in XML document from (no description) is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" is not declared.
org.xml.sax.SAXParseException: Element type "bean" is not declared.
	at org.apache.crimson.parser.Parser2.error(Unknown Source)
	at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
	at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
	at org.apache.crimson.parser.Parser2.parse(Unknown Source)
	at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
	at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
	at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:126)
	at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:84)
	at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:72)
	at teste.Teste.main(Teste.java:19)
Exception in thread "main"

O que poderia estar errado?
O elemento “bean” está definido corretamente, não está?

Alguém tem alguma idéia?

Gabriel.

Criado 1 de setembro de 2004
Respostas 0
Participantes 1