Cześć,
Uczę się springa na podstawie książki "Spring w akcji - Wydanie IV" i napotkałem pierwszy problem z którym nie mogę sobie poradzić.
Mam klase SlayDragonQuest która w konstrukturze dostaje PrintStream:
package com.springinaction.knights;
import java.io.PrintStream;
public class SlayDragonQuest implements Quest {
private PrintStream stream;
public SlayDragonQuest(PrintStream stream) {
this.stream = stream;
}
@Override
public void embark() {
stream.println("Embarking on quest to slay the dragon!");
}
}
Plik konfiguracyjny Springa wygląda tak:
<?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="knight" class="com.springinaction.knights.BraveKnight">
<constructor-arg ref="quest"/>
</bean>
<bean id="quest" class="com.springinaction.knights.SlayDragonQuest">
<constructor-arg ref="#{T(System).out}"/>
</bean>
</beans>
Kontekst aplikacji:
package com.springinaction.knights;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class KnightMain {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("knights.xml");
Knight knight = (Knight) context.getBean("knight");
knight.embarkOnQuest();
context.close();
}
}
Błędy (całość - http://pastebin.com/5a7dT0gT):
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'knight' defined in class path resource [knights.xml]: Cannot resolve reference to bean 'quest' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'quest' defined in class path resource [knights.xml]: Cannot resolve reference to bean '#{T(System).out}' while setting constructor argument;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'java.io.PrintStream@731a74c' is defined
Co może być nie tak z #{T(System).out}?
Proszę o pomoc lub ew. podpowiedzi.