Spring在配置类中声明的2个bean之间是混乱的,因此您可以使用
@Qualifier批注以及
@Autowired通过指定要连接的确切bean来消除混乱,将这些修改应用于配置类
@Configurationpublic class SpringConfig { @Bean(name="clazzImplA") public baseInterface clazzImplA(){ return new ClazzImplA(); } @Bean(name="clazzImplB") public baseInterface clazzImplB(){ return new ClazzImplB(); }}然后在
@autowired注解
@Service@SpringApplicationConfiguration(SpringConfig.class)public class AutowiredClazz { @Autowired @Qualifier("the name of the desired bean") private baseInterface baseInterface; private AutowiredClazz(baseInterface baseInterface){ this.baseInterface = baseInterface; }}


