站长资源网络编程

JSP 获取Spring 注入对象示例

整理:jimmy2024/10/27浏览2
简介<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%><%@ page import="org.springframework.context.ApplicationContext
<%@ 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");