Fork me on GitHub
16 Jul 2015 Comments

在Spring中获取ServletContext方法

注意:下面代码是在web环境中才能获取到WebApplicationContext,ContextLoader为spring中创建applicaitonContext上下文的类,而applicationContext是spring的核心

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); ServletContext servletContext = webApplicationContext.getServletContext();

原创文章,转载请注明:转载自:在Spring中获取ServletContext方法