关于spring配置文件的读取方式

来源: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); 
}
 

你可能感兴趣的:(spring,.net,xml,servlet)