第一种方式(in hedao):
/**
* 获取Spring对象的公共方法
*
* @author luoyue
*
*/
public class BeanHolder {
public static Object getBean(String beanId) {
WebApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(ApplicationContext
.getContext().getServletContext());
return ctx.getBean(beanId);
}
}
第二种方式(in yingbo):
ApplicationContext ac = new FileSystemXmlApplicationContext("E:/Workspaces/MyEclipse 10/crawler/resources/applicationContext.xml");
TaskDistributor taskDistributor = (TaskDistributor)ac.getBean(beanId);
beanId 为spring配置文件中javabean的id