That you should work with @Resource or @Autowired in the setter should introduce all instances of Color in the List<Color> field.
If you want to be more explicit, you can return the collection as another bean:
@Bean public List<Color> colorList(){ List<Color> aList = new ArrayList<>(); aList.add(blue()); return aList; }
and use it as an autoset field like this:
@Resource(name="colorList") public void setColors(List<Color> colors) { this.colors = colors; }
OR
@Resource(name="colorList") private List<Color> colors;
The question of returning an interface or implementation needs to work, but the interface should be preferred.
Biju kunjummen
source share