nevergiveupzeng

导航

Spring容器中获取bean实例的方法

 

// 得到上下文环境
WebApplicationContext webContext = ContextLoader .getCurrentWebApplicationContext();
// 使用上下文环境中的getBean方法得到bean实例
InhospDoctorStationController controller = (InhospDoctorStationController) webContext.getBean("inhospDoctorStationController");
 
上面的例子是spring容器中,得到注册的jsf bean的例子,大概就是用第二行中的代码,得到上下文环境,然后再使用webContext.getBean()方法,参数为注册时使用的名字,得到spring容器中的实例。

posted on 2015-11-21 15:20  nevergiveupzeng  阅读(751)  评论(0)    收藏  举报