Autowiring a bean manually with Spring

When creating a functional test that uses Spring and a resource, such as DB2, it's helpful to have a common context file which defines my ConnectionFactory to the database. But I need a way to inject that factory into my DAO. In general, I try not to use XML configuration, so how do I get my DAO to autowire? Enter the ApplicationContextAware class.

Here's a Spock test that autowires the DAO objects.

@ContextConfiguration(locations = ['classpath:db2ResourceContext.xml'])
public class Tester extends Specification implements ApplicationContextAware {

  @Shared
  private MyDAO dao = new MyDAO()
  
  def 'My Test'() {
    //use the dao confident the connection factory has been autowired
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) {
    applicationContext.autowireCapableBeanFactory.autowireBean(dao)
  }
}