IT码农库

您当前所在位置:首页 > 网络编程 > JSP编程

JSP编程

JSP 获取Spring 注入对象示例

网络 1970-01-01JSP编程1672
这篇文章主要介绍了JSP如何获取Spring 注入对象,实现代码如下,需要的朋友不要错过
<%@ 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");

大图广告(830*140)