Spring

jsp 에서 applicationcontext 얻어와서 getBean 사용하기.

티-스토리 2012. 11. 13. 11:33

Spring Context 관련 import

<%@ page import="
             org.springframework.web.context.*,
             org.springframework.web.context.support.*"%>


Spring WebApplicationContext 가져오기

<%
   ServletContext ctx = pageContext.getServletContext();
   WebApplicationContext wac =
         WebApplicationContextUtils.getRequiredWebApplicationContext(ctx);
%>


Spring Bean 호출하기

// getBean
   XXX xxx = (XXX) wac.getBean("xxx");
   xxx.doSomething();