| 15 | import javax.servlet.http.*; |
| 16 | |
| 17 | @Controller |
| 18 | public class HomeController { |
| 19 | @Autowired |
| 20 | WebApplicationContext servletAC; // Servlet AC |
| 21 | |
| 22 | @RequestMapping(value = "/", method = RequestMethod.GET) |
| 23 | public String home(Locale locale, HttpServletRequest request, Model model) { |
| 24 | // 원래는 request.getServletContext()지만, 컨트롤러는 HttpServlet을 상속받지 않아서 아래와 같이 해야함. |
| 25 | ServletContext sc = request.getSession().getServletContext(); // ApplicationContextFacade |
| 26 | WebApplicationContext rootAC = WebApplicationContextUtils.getWebApplicationContext(sc); // Root AC |
| 27 | |
| 28 | System.out.println("webApplicationContext = " + rootAC); |
| 29 | System.out.println("servletAC = " + servletAC); |
| 30 | |
| 31 | System.out.println("rootAC.getBeanDefinitionNames() = " + Arrays.toString(rootAC.getBeanDefinitionNames())); |
| 32 | System.out.println("servletAC.getBeanDefinitionNames() = " + Arrays.toString(servletAC.getBeanDefinitionNames())); |
| 33 | |
| 34 | System.out.println("rootAC.getBeanDefinitionCount() = " + rootAC.getBeanDefinitionCount()); |
| 35 | System.out.println("servletAC.getBeanDefinitionCount() = " + servletAC.getBeanDefinitionCount()); |
| 36 | |
| 37 | System.out.println("servletAC.getParent()==rootAC = " + (servletAC.getParent() == rootAC)); // servletAC.getParent()==rootAC = true |
| 38 | return "home"; |
| 39 | } |
| 40 | } |
| 41 | /* [실행결과] |
| 42 | webApplicationContext = Root WebApplicationContext: startup date [Thu Jan 06 16:26:50 KST 2022]; root of context hierarchy |
| 43 | servletAC = WebApplicationContext for namespace 'appServlet-servlet': startup date [Thu Jan 06 16:26:51 KST 2022]; parent: Root WebApplicationContext |
nothing calls this directly
no outgoing calls
no test coverage detected