在jsp中获得 Spring的上下文

来源:互联网 发布:知乎 污 编辑:程序博客网 时间:2024/06/10 13:20
在jsp中获得 Spring的上下文
在Struts或别的框架中集成Spring的时候,Spring向我们提供了获得context的方法 getApplicationContext,那在jsp中如何获得呢?

ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext
(
this.getServletConfig().getServletContext());

建议在项目中开发的时候提供一个singleton对外公布统一的applicationContext,毕竟不是每个人都一定能获得web环境或servlet.