title: no such bean definition exception in spring
body: <p>I am new to the concepts of Spring and Hibernate.
  I am using collections in my simple spring program. My idea is to store an author name, address and id into collection. It's a simple spring framework but I am struck with one error.</p>
  
  <p>spring-model.xml</p>
  
  <pre><code>&lt;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.5.xsd"&gt;
  
      &lt;bean id="book" class="com.vishal.Book"&gt;
          &lt;property name="author "&gt;
              &lt;list&gt;
                  &lt;ref bean="book1 " /&gt;
                  &lt;ref bean="book2 " /&gt;
                  &lt;ref bean="book3 " /&gt;    
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="book1" class="com.vishal.Book"&gt;
          &lt;property name="name" value="mark twain" /&gt;
          &lt;property name="address" value="London" /&gt;
          &lt;property name="id" value="230" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="book2" class="com.vishal.Book"&gt;
          &lt;property name="name" value="gutav friedman" /&gt;
          &lt;property name="address" value="Germany" /&gt;
          &lt;property name="id" value="231" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="book3" class="com.vishal.Book"&gt;
          &lt;property name="name" value=" Erastothe " /&gt;
          &lt;property name="address" value="spain" /&gt;
          &lt;property name="id" value="232" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>main class</p>
  
  <pre><code>package com.vishal;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class Springmain {
  
      @SuppressWarnings("resource")
      public static void main(String[] args) {
          ApplicationContext context = new ClassPathXmlApplicationContext(
                  "spring-model.xml");
          Book book = (Book) context.getBean("book");
          book.authorName();
      }
  
  }
  </code></pre>
  
  <p>book.java</p>
  
  <pre><code>package com.vishal;
  
  import java.util.List;
  
  public class Book {
  
      private List&lt;Author&gt; author;
  
      public List&lt;Author&gt; getAuthor() {
          return author;
      }
  
      public void setAuthor(List&lt;Author&gt; author) {
          this.author = author;
      }
  
      public void authorName() {
          for (Author authors : author)
              System.out.println(authors.getAddress() + authors.getId()
                      + authors.getName());
      }
  }
  </code></pre>
  
  <p>author class</p>
  
  <pre><code>package com.vishal;
  
  public class Author {
      private String name;
      private String address;
      private int id;
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>Following is the error which I a getting</p>
  
  <pre><code>Jun 10, 2013 11:29:36 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
  INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@161d36b: startup date [Mon Jun 10 11:29:36 IST 2013]; root of context hierarchy
  Jun 10, 2013 11:29:36 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  INFO: Loading XML bean definitions from class path resource [spring-model.xml]
  Jun 10, 2013 11:29:37 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1b5998f: defining beans [book,book1,book2,book3]; root of factory hierarchy
  Jun 10, 2013 11:29:37 AM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
  INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1b5998f: defining beans [book,book1,book2,book3]; root of factory hierarchy
  Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'book' defined in class path resource [spring-model.xml]: Cannot resolve reference to bean 'book1 ' while setting bean property 'author ' with key [0]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'book1 ' is defined
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1134)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
      at com.vishal.Springmain.main(Springmain.java:10)
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'book1 ' is defined
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1102)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)
      ... 17 more
  </code></pre>