Spring autowire a list

Spring 4 and older support the ability to automatically collect all beans of a given type and inject them into a collection or array.

Here is an example:

@Component
public class Car implements Vehicle {
}

@Component
public class Bus implements Vehicle {
}

@Component
public class User {
   @Autowired
   List<Vehicle> vehicles; // contains both car and bus
}

Ref: Spring 4 Ordering Autowired Collections

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)