title: Bean definition in junit configuration file
body: <p>I'm using junit to test some one of my services. I use spring to inject the service and all it's dependencies. My test class looks like the folowing.</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:/location/MyServiceTest-context.xml"})
  @Transactional
  public class MyServiceTest extends TestSupport {
  
      @Autowired
      private MyService myService;
  
      @Test
      public void testX() throws Exception {
          ...
      }
  }
  </code></pre>
  
  <p>The configuration file is:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans      
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
  
       &lt;bean id="entityBasePackages" class="java.lang.String"&gt;
           &lt;constructor-arg value="com.package1.model"/&gt;
       &lt;/bean&gt;
  
       &lt;bean id="bean1" class="org.easymock.EasyMock" factory-method="createMock"&gt;
           &lt;constructor-arg value="com.package2.bean1"/&gt;
       &lt;/bean&gt;
  
       &lt;bean id="bean2" class="org.easymock.EasyMock" factory-method="createMock"&gt;
           &lt;constructor-arg value="com.package3.bean2"/&gt;
       &lt;/bean&gt;
  
       &lt;context:component-scan base-package="com.package4.MyService"/&gt;
  
   &lt;/beans&gt;
  </code></pre>
  
  <p>MyService uses a bean1. bean1 depends on bean2, that is, it uses it. When i run my test like this, it works fine. However, if i declare bean2 above bean1 in my configuration xml, the test fails with a </p>
  
  <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.package2.bean1]
  </code></pre>
  
  <p>I guess Spring reads the file and when it gets to a bean definition, tries to wire it - that's why it crashes in my case. Is there a way to tell Spring to read the entire file and then try to wire the beans? This way i could write my bean definitions without worrying about their order. Thanks</p>