当前位置: 代码迷 >> JavaScript >> 在jsp页面下,怎么从spring容器中拿到一个bean
  详细解决方案

在jsp页面下,怎么从spring容器中拿到一个bean

热度:294   发布时间:2012-10-09 10:21:45.0
在jsp页面上,如何从spring容器中拿到一个bean
<%WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this

.getServletContext());

System.out.println("===========初始化成功=========");

worksService = (SomeServiceImpl) wac.getBean("someService");%>



spring部分代码:

String attrName=WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;//值为:
"org.springframework.web.context.WebApplicationContext.ROOT"

Object attr = sc.getAttribute(attrName);
return (WebApplicationContext)attr ;
  相关解决方案