M
M
Maks Burkov2017-04-10 02:09:43
Java
Maks Burkov, 2017-04-10 02:09:43

Why can't it find my Bean?

Not understandable Exception, can anyone come across? I don't get any warnings , the bean itself seems to be defined correctly.

<bean id="chosen" class="maks.example2.City">
        <property name="chosenCity" value="#{cities[2]}"/>
    </bean>

    <util:list id = "cities">
        <bean class="maks.example2.City" p:name="Chicago" p:state="IL" p:population="2853114"/>
        <bean class="maks.example2.City" p:name="Atlanta" p:state="GA" p:population="537958"/>
        <bean class="maks.example2.City" p:name="Dallas" p:state="TX" p:population="1279910"/>
        <bean class="maks.example2.City" p:name="Houston" p:state="TX" p:population="2242193"/>
        <bean class="maks.example2.City" p:name="Odessa" p:state="TX" p:population="90943"/>
        <bean class="maks.example2.City" p:name="El Paso" p:state="TX" p:population="613190"/>
        <bean class="maks.example2.City" p:name="Jal" p:state="NM" p:population="1996"/>
        <bean class="maks.example2.City" p:name="Las Cruces" p:state="NM" p:population="91865"/>
    </util:list>

main:
Instrumentalist kenny =  context.getBean("kenny",Instrumentalist.class);
        Instrumentalist carl =  context.getBean("carl",Instrumentalist.class);
        System.out.println("Kenny: "+kenny.getInstrument().getClass().getName()); // WORKING
        System.out.println("Carl: "+carl.getInstrument().getClass().getName()); // WORKING
        City city = context.getBean("chosen",City.class); // CAN'T FIND! 
        System.out.println("Chosen city: "+city.getChosenCity());

console output:
Application loading! 
Kenny: maks.example2.Piano
Carl: maks.example2.Saxophone
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'chosen' is defined

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question