美文网首页
Spring MVC 获取WebApplicationConte

Spring MVC 获取WebApplicationConte

作者: else05 | 来源:发表于2016-05-09 21:38 被阅读710次

    不用依赖ServletContext

    // 取得WebApplicationContext
    WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
    
    // 取出Bean
    webApplicationContext.getBean("xxx",xxx.class) ;
    
    // 取出ServletContext
    ServletContext servletContext = webApplicationContext.getServletContext();
    
    

    相关文章

      网友评论

          本文标题:Spring MVC 获取WebApplicationConte

          本文链接:https://www.haomeiwen.com/subject/vhberttx.html