Configure Implementation Class of Abstract Factory with Spring

后端 未结 3 1730
遥遥无期
遥遥无期 2020-12-30 17:13

For my application, I have a Scale interface and multiple classes implementing this interface, for example NormalizedScale, LogScale,

3条回答
  •  无人及你
    2020-12-30 17:53

    You can simply use "Qualifiers" which is basically going to point to a specific "named" bean. By default the bean names are the name of your classes, with the first letter in lower case (MyClass -> myClass). If you want to define your own names you can do as follow :

    @Service("customizedBeanName")
    

    You would end up doing something like this :

    @Autowired
    @Qualifier("logScale")
    private Scale logScale;
    
    @Autowired
    @Qualifier("anotherScale")
    private Scale anotherScale;
    

提交回复
热议问题