在servlet中
private ApplicationContext ctx;
public void init() throws ServletException {
ctx = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
Bean bean= ctx.getBean("Bean",Bean.class);
}
在JSP中
ServletContext context = request.getSession().getServletContext();
ApplicationContext ctx= WebApplicationContextUtils.getWebApplicationContext(context);
Bean bean=(Bean)ctx.getBean("beanName");