Spring: Attaching @Qualifer to Java-configured beans

和自甴很熟 提交于 2019-11-29 03:27:23

If you're using annotations (not Java based configuration), you can use the following to add a qualifier (see the Spring documentation):

@Component
@Qualifier("myQualifier")
public class MyBean {
    //code
}

And to wire in the bean, use the following (again, see the Spring documentation):

public class MyClass {

    @Autowired
    @Qualifier("myQualifier")
    private MyBean myBean;

    //more code

}

What, like @Qualifier, you mean?

3.10.4 Defining bean metadata within components

Example:

  @Bean @Qualifier("public")
  public TestBean publicInstance() {
      return new TestBean("publicInstance");
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!