JSP获取Spring管理的bean

<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.context.ApplicationContext"%>web

 

ServletContext sc = this.getServletConfig().getServletContext();
 ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(sc);
 要获取的对象 serv = (要获取的对象) ac2.getBean("spring配置文件中的id");//或根据类型获取spring

相关文章
相关标签/搜索