title: Spring 3 - Dynamic Autowiring at runtime based on another object attribute
body: <p>I am working on a Spring 3.1 MVC application and for one of my scenarios, I had to write two implementations of a DAO. I would like to know how to autowire this in a service layer
   based on another object's attribute.</p>
  
  <p>For example,</p>
  
  <pre><code>    class Vehicle {
          private name;
          private type;
          ..
          ..
          ..
      } 
  
      @Service
      class VehicleServiceImpl implements VehicleService {
  
              // There are two implementations to this DAO
              // if Vehicle.type == "CAR", inject CarDAO
              // if Vehicle.type == "TRAIN", inject TrainDAO 
              @Autowired
              private VehicleDAO vehicleDAO ;
  
      }
  
      @Repository
      class CarDAO implements VehicleDAO {
  
      }
  
      @Repository
      class TrainDAO implements VehicleDAO {
  
      }
  </code></pre>
  
  <p>If my Vehicle is a Car, I need to autowire CarDAO and if it's a train, I need to autowire TrainDAO</p>
  
  <p>What is the best way to implement this in spring 3.1.</p>
  
  <p>I was hoping to use either context property place holders or  @Qualifier annotation but both these are kind of restricted to lookup based on some property. 
  I am not sure how to do this at runtime based on the property of another object.</p>