哪个是CDI @Produces注释的Spring等价物?

当我使用CDI时,我可以使用@Produces批注创建一个生成器方法来调用,以选择实现接口的bean将由@Inject批注注入。

现在我正在使用Spring,但我没有找到类似的东西。 当我使用@Autowired注释时,我需要使用什么来获得与CDI中@Produces注释相同的结果?

你在找@Bean

@Bean是方法级注释,是XML元素的直接模拟。 注释支持大多数提供的属性,例如:init-method,destroy-method,autowiring,lazy-init,dependency-check,depends-on和scope。

示例(取自上面的链接):

 @Configuration public class AppConfig { //similar to @Produces CDI annotation @Bean public TransferService transferService() { return new TransferServiceImpl(); } } 

我建议你读一读: Spring DI和CDI比较研究