有一个接口IService 他有2个实现类Iservice1和iservice2
在spring中配置2个实现类的实例:然后利用
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(getServletContext());
Map<String, DsmAction> beansOfType = context.getBeansOfType(IService.class);注意context.getBeansOfType(IService.class);这里写的是接口的class对象,这个这个map中就有2个这个接口的实现类对象了..
本文介绍如何在Spring框架中通过接口获取其实现类的实例。具体实践为配置IService接口及其两个实现类IService1和IService2,在运行时通过WebApplicationContext获取所有实现IService接口的Bean。
150

被折叠的 条评论
为什么被折叠?



