JSP 获取Spring 注入对象示例

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

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

ServletContext sc = this.getServletConfig().getServletContext();
ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(sc);

要获取的对象 serv = (要获取的对象) ac2.getBean("spring配置文件中的id");


代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!