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;}}