title: What's the difference between @Autowired and getting a bean from the application context?
body: <p>I have a dao unit test that is declared as follows:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:spring/applicationContext.xml"})
  @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  @Transactional
  public class RegisterDaoTest extends AbstractTransactionalJUnit4SpringContextTests {
  
      ApplicationContext applicationContext = new     FileSystemXmlApplicationContext("classpath:/spring/applicationContext.xml");
      private IRegisterDao registerDao = applicationContext.getBean(IRegisterDao.class);
  </code></pre>
  
  <p>When I run the unit test, all pass and I can see the db getting recreated in between unit test executions.</p>
  
  <p>My test db is defined as follows:</p>
  
  <pre><code>    &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver"/&gt;
      &lt;property name="url" value="jdbc:hsqldb:mem:test;sql.syntax_ora=true;create=true"/&gt;
      &lt;property name="username" value="sa"/&gt;
      &lt;property name="password" value=""/&gt;
  &lt;/bean&gt;
  
  &lt;jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS"&gt;
      &lt;jdbc:script location="file:Artifacts/Hsql Version Scripts/install/droptables.sql" separator=";"/&gt;
      &lt;jdbc:script location="file:Artifacts/Hsql Version Scripts/install/install.sql" separator="/;"/&gt;
  &lt;/jdbc:initialize-database&gt;
  </code></pre>
  
  <p>But when I change my test to use @Autowired, defined below, it does not execute the init db scripts.</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:spring/applicationContext.xml"})
  @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  @Transactional
  public class RegisterDaoTest extends AbstractTransactionalJUnit4SpringContextTests {
  
  /*
  ApplicationContext applicationContext = new FileSystemXmlApplicationContext("classpath:/spring/applicationContext.xml");
      private IRegisterDao registerDao = applicationContext.getBean(IRegisterDao.class);
  */
  
      @Autowired
      private IRegisterDao registerDao;
  </code></pre>
  
  <p>I don't see what the difference is.  I have two applicationContext.xmls, one in the main and one in the test (so I can override the db with the test db)</p>
  
  <p>To me, it should execute the same.  Am I missing something?</p>
  
  <p>Thanks,</p>