接上一篇@Autowired和@Resource的使用区别介绍,本片继续介绍一项我新学到的Spring技巧。
在业务代码中,我们经常会使用到策略模式,同一接口可能会有不同的实现类,已完成不同bean实例的创建。通常我们希望根据传入的参数来决定使用的bean实例。话不多说,直接上代码:
@RestController
public class TestController {
@Resource
private TestService testService1;
@Autowired
ApplicationContext applicationContext;
@Autowired
Map