当前位置: 代码迷 >> Web前端 >> WEBService种中获取SpringIOC
  详细解决方案

WEBService种中获取SpringIOC

热度:80   发布时间:2012-09-22 21:54:54.0
WEBService类中获取SpringIOC
MessageContext mc = MessageContext.getCurrentContext();
  HttpServletRequest req = (HttpServletRequest) mc.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
  ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(req.getSession().getServletContext());
  QueryServiceImpl service = (QueryServiceImpl)ctx.getBean("queryService");

?

?

前提是需要在web.xml中已有加载spring IOC的配置,这样不管你配置文件放在什么位置都可以获取到了,

  相关解决方案