首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

SpringAppContext单例调用服务种

2012-10-23 
SpringAppContext单例调用服务类/*** action 中的使用*/public ActionForward query(ActionMapping mappin

SpringAppContext单例调用服务类

/*** action 中的使用*/public ActionForward query(ActionMapping mapping, ActionForm actionForm,HttpServletRequest request, HttpServletResponse response)throws Exception {CsbCpxzForm myForm = (CsbCpxzForm) actionForm;CsbCpxzService serv = (CsbCpxzService) SpringAppContext.getBean(CsbCpxzService.KEY,request);}
/** *  */package com.example.spring;import javax.servlet.http.HttpServletRequest;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;public class SpringAppContext {private static ApplicationContext instance;private static String[] minorConfig={ };static public Object getBean(String beanId, HttpServletRequest request){ ApplicationContext app = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext()); return app.getBean(beanId);}private SpringAppContext() {}static public ApplicationContext getInstance() {if (instance == null) {instance =  new ClassPathXmlApplicationContext(minorConfig);}return instance;}}




热点排行