Bean constructor-arg System.out

0

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.

2

Przypadkiem to nie działa tak, że jak podajesz ref="" to powinieneś stworzyć beana z id?
Chyba powinieneś dać coś takiego jak constructor-arg value?

1 użytkowników online, w tym zalogowanych: 0, gości: 1