当前位置: 代码迷 >> Web前端 >> servlet 中取得spring Bean 的方法
  详细解决方案

servlet 中取得spring Bean 的方法

热度:316   发布时间:2012-08-21 13:00:21.0
servlet 中获得spring Bean 的方法

?

?

?

只需要servlet 中的servletContext 对象作为参数 就可以获得spring中的bean对象,方法如下:

?

public static Object getBean(String name, ServletContext context) {
        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
        return ctx.getBean(name);
    }
?
  相关解决方案