728x90
[web.xml] <context-param> <param-name>contextConfigLocation</param-name> <param-value> <param-value>/WEB-INF/spring/root-context.xml</param-value> </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> |
web.xml에 설정된 파라미터를 getInitParameter()메서드를 통해 참조할 수도 있지만
단순 문자열이 아닌 객체를 참조하는 방법이 listener이다.
프로그래밍에서의 listener은 귀 기울여 기다리다가 실행되는 컴포넌트(메소드나 함수)를 말한다.
리스너는 이벤트가 발생함과 동시에 특정 행동을 하는데,
이걸 이벤트 핸들링이라고 한다.
위 박스에서 listener에 적힌 ContextLoaderListener은 2개 이상의 dispatcherServlet를 생성했을때 필요하다.
ContextLoaderListener를 선언하지 않고 dispatcherServlet을 A,B 두개를 선언하면 각각의 독립적인 context를 가지게 된다.
근데 만약 A와 B 둘 모두에게 필요한 bean이 있어야 한다면 전역Context를 만들고 그안에 bean을 생성하면 어디서든 접근이 가능해진다.
이때, ContextLoaderListener을 사용해 전역 Context를 생성해 줄 수 있다.
출처 : https://pangtrue.tistory.com/136
https://pangtrue.tistory.com/136
출처 : 코끼리를 냉장고에 넣는 방법 :: [서블릿/JSP] 리스너(Listner)란? 이벤트 리스너의 개념 설명. 구현 및 등록하기 (tistory.com)
728x90
'Spring' 카테고리의 다른 글
[spring] contextConfigLocation 이란 (0) | 2021.11.11 |
---|---|
web, WEB-INF 차이점 (0) | 2021.08.24 |
(추가 필요@RequestBody )@ResponseBody, @RequestMapping, @RequestParam, @ModelAttribute (0) | 2021.01.09 |
1/06 스프링 chapter06 (0) | 2021.01.06 |
1/04 스프링 (0) | 2021.01.04 |