转
http://omencathay.itpub.net/post/30163/443031
/**第一种 */
ApplicationContext ac = new FileSystemXmlApplicationContext("serviceContext.xml");
JurisdictionImp jurisdictionImp = (JurisdictionImp)ac.getBean("jurisdictionImp");
/**第二种*/
FileSystemXmlApplicationContext ctx =new FileSystemXmlApplicationContext(CONTEXT_FILE);
JurisdictionImp jurisdictionImp = (JurisdictionImp) ctx.getBean("jurisdictionImp");
/**第三种*/
Resource resource = new ClassPathResource(CONTEXT_FILE);
XmlBeanFactory beanFactory = new XmlBeanFactory( resource);
JurisdictionImp jurisdictionImp=(JurisdictionImp) beanFactory.getBean("jurisdictionImp");
/**第四种*/
ServletContext context=request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
JurisdictionImp jurisdictionImp=(JurisdictionImp) ctx.getBean("jurisdictionImp");
/**第五种*/
/**
* 获得其它业务类对象
* */
public Object getBean(String name)
{
WebApplicationContext ctx
if (ctx == null)
{
ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(servlet.getServletContext());
}
return ctx.getBean(name);
}
posted on 2008-07-09 11:13
Libo 阅读(851)
评论(0) 编辑 收藏 所属分类:
Spring