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 ");

你可能感兴趣的:(servlet)