读书人

servlet 中取得spring Bean 的方法

发布时间: 2012-08-21 13:00:21 作者: rapoo

servlet 中获得spring Bean 的方法

?

?

?

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

?

public static Object getBean(String name, ServletContext context) {        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);        return ctx.getBean(name);    }
?

读书人网 >Web前端

热点推荐