Spring autowire interface

后端 未结 2 1355
孤城傲影
孤城傲影 2020-12-06 02:37

I have an Interface IMenuItem

public interface IMenuItem {

    String getIconClass();
    void setIconClass(String iconClass);

    String getLink();
    vo         


        
2条回答
  •  一个人的身影
    2020-12-06 03:04

    i believe half of job is done by your @scope annotation , if there is not any-other implementation of ImenuItem interface in your project below will create multiple instances

    @Autowired
    private IMenuItem menuItem
    

    but if there are multiple implementations, you need to use @Qualifer annotation .

    @Autowired
    @Qualifer("MenuItem")
    private IMenuItem menuItem
    

    this will also create multiple instances

提交回复
热议问题