servlet中获取spring context, 获取bean

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


//struts2 获取ServletContext  ServletActionContext.getServletContext();
ServletContext application = getServletContext();
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);
XyManager flightTicketManager = (XyManager) wac.getBean("xyManager ");

猜你喜欢

转载自jerryzxm.iteye.com/blog/1766974