@Qualifier Annotation in Spring is not working

Both your method and field are annotated with @Autowired. As such, Spring will try to inject both. On one of the runs, it will try to inject

@Autowired
@Qualifier("nasigoreng")
private Food food;

which will work because the injection target is qualified.

The method however

@Autowired
public void setFood(Food food) {
    this.food = food;
}

does not qualify the injection parameter so Spring doesn't know which bean to inject.

Change the above to

@Autowired
public void setFood(@Qualifier("nasigoreng") Food food) {
    this.food = food;
}

But you should decide one or the other, field or setter injection, otherwise it is redundant and may cause errors.


Try only removing @Autowired from setFood() in PecintaKuliner

like

@Autowired
@Qualifier("nasigoreng")
private Food food;

public void setFood(Food food) {
    this.food = food;
}

I tried with Spring 4.2.4. Problem resolved just by adding <context:annotation-config /> in configuration file.