contextConfigLocation - 스프링프레임 워크가 동작하기 위한 설정파일의 위치를 알려주는 파라미터 contextConfigLocation이라는 파라미터를 사용하면 Context Loader가 load할 수 있는 설정파일을 쓸 수 있다. |
ContextLoaderListener - 스프링에서 제공하는 클래스중 하나로 ContextLoader와 ServletContextListener를 상속하고 있다. 서블릿 컨테이너 생명주기에 맏춰서 spting의 application context를 servlet attribute에 등록하고 제거한다 |
스프링 프레임워크가 동작하려면 가장 기본적으로 web.xml 파일에 스프링 설정 파일을 명시해 줘야 한다.
스프링 설정파일을 읽어들이기 위해서는 org.springframework.web.context.ContextLoaderListener가 필요하다.
이 리스너가 동작해야 설정파일을 읽어들이고 필요한 객체들을 등록하고 만들 수 있다.
그럼 리스너가 동작하기 위해서 설정파일의 위치를 알려줘야 한다.
그래서 <context-param>안에 contextConfigLocation이라고 해서 파라미터와 위치를 지정해 준다.
하나의 파일이든 여러개든 명시해서 읽어올 수 있다.
(= Context Loader가 load할 수 있는 설정파일을 여러개 쓸 수 있다.)
설정파일 안에는 dataSource, bean(dao, service)등 필요한 객체들이 들어있다.
여기서 또 ContextLoaderListener가 뭐냐면
ContextLoaderListener - 스프링에서 제공하는 클래스중 하나로 ContextLoader와 ServletContextListener를 상속하고 있다. 서블릿 컨테이너 생명주기에 맏춰서 spting의 application context를 servlet attribute에 등록하고 제거한다 = WAS구동시에 web.xml을 읽어들여 웹 어플리케이션 설정을 구성하기위한 즉, 초기셋팅작업을 해주는 역할 |
ContextLoaderListener의 역할
- ContextLoaderListener 와 DispatcherServlet 은 각각 WebApplicationContext 를 생성하는데, 스프링에서 사용되는 Context 간의 계층 관계를 연결해주는 부분
- 웹 어플리케이션이 시작되고 종료되는 시점에 Servlet Context가 생성하는 이벤트를 연결
- Servlet WebApplicationContext 에서는 Root WebApplicationContext 를 참조 가능하지만, 그 반대로 참조 불가
[web.xml] <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> |
출처 : BlueMoon... : org.springframework.web.context.ContextLoaderListener (egloos.com)
https://developer-latteya.tistory.com/21
<context-param>은 sts에서 기본적으로 제공해주는 설정 파일외에, 사용자가 직접 컨트롤하는 XML파일을 지정해주는 역활을 한다.
위 박스에서 설정되어 있는 root-content.xml은 모든 서블릿과 필터에서 사용되는 루트 스프링 컨테이너에 대한 설정이다.
위 박스의 listener는 스프링 설정 정보를 읽는다.
https://galid1.tistory.com/524
'Spring' 카테고리의 다른 글
[spring] ContextLoaderListener란 (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 |