servlet 中取得spring Bean 的方法

servlet 中获得spring Bean的方法???只需要servlet 中的servletContext 对象作为参数 就可以获得spring中

servlet 中获得spring Bean 的方法

?

?

?

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

?

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