Spring动态获取已注入的对象的方法

1、根据类获取对象

@Autowired
 ApplicationContext context;

GenericMapper<T,String> dao=(GenericMapper<T,String>)context.getBean(TestDaoImpl.class);

2、根据接口获取实现类的对象

@Autowired
ApplicationContext context;


GenericMapper<T,String> dao=(GenericMapper<T,String>)context.getBean(TestInterface.class);

 

posted @ 2019-01-22 01:27  oliverreal  阅读(1501)  评论(0)    收藏  举报