获得ApplicationContext的方法:
(1)如果是在Test测试的类中需要加载ApplicationContex时候用。
public static ApplicationService getApplicationService() {
if(ctx == null){
ctx=new ClassPathXmlApplicationContext("*spring*.xml");
}
if(applicationService == null){
applicationService = (ApplicationService) ctx.getBean("applicationService");
}
return applicationService;
}
(2)如果是在项目中,启动了服务器以后需要ApplicationContex,则直接取此对象,不需要再加载文件。
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.pageContext.getServletContext());
ApplicationService applicationService = (ApplicationService) wac.getBean("applicationService");
List<Application> list = applicationService.findListByLoginName(loginName);