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.

For example,

    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 {

    }

If my Vehicle is a Car, I need to autowire CarDAO and if it's a train, I need to autowire TrainDAO

What is the best way to implement this in spring 3.1.

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.

Edit
Report