# 1.15.4 웹 어플리케이션에 대한 간편한 Application 인스턴스화 by sh

### **1.15.4.** 웹 어플리케이션을 위한 편리한 ApplicationContext 인스턴스화

예를 들어, **`ContextLoader`를 사용하여 선언적으로 `ApplicationContext`인스턴스를 만들 수 있습니다.** 물론, `ApplicationContext`구현 중 하나를 사용하여 프로그래밍 방식으로 `ApplicationContext`인스턴스를 만들 수도 있습니다.&#x20;

다음 예제와 같이, `ContextLoaderListener`를 사용하여 `ApplicationContext`를 등록할 수 있습니다:&#x20;

```markup
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
```

**리스너는 `contextConfigLocation`매개 변수를 검사합니다. 매개 변수가 존재하지 않으면, 리스너는 `/WEB-INF/applicationContext.xml`을 기본 값으로 사용합니다. 매개 변수가 존재하면 리스너는 미리 정의된 구분 기호(쉼표, 세미콜론 및 공백)를 사용하여 문자열을 구분하고 이 값을 응용 프로그램 컨텍스트를 검색할 위치로 사용합니다.** Ant 스타일 경로 패턴도 지원됩니다. 예는`/WEB-INF/*Context.xml`(이름이 `Context.xml`로 끝나고 WEB-INF 디렉토리에 있는 모든 파일의 경우) 및`/WEB-INF/**/*Context.xml`(모든 WEB-INF의 하위 디렉토리에 있는 파일) 입니다.&#x20;

{% hint style="info" %}

* **ContextLoaderListener Vs. ContextLoaderServlet**&#x20;

  * 스프링에서 모든 서블릿에서 사용될 공유 자원을 DI 개념으로 사용하기 위해 ContextLoader를 구현한 두 가지의 클래스를 제공한다.&#x20;

    * ContextLoaderServlet -> Servlet 2.2나 2.3에서 사용 권장.&#x20;
    * ContextLoaderListener -> Servlet 2.4 이상에서 사용 권장.&#x20;

    WAS 에서 지원하는 서블릿 버전 확인해서 그에 맞게 사용해야 한다.&#x20;

  &#x20;       Cf. 톰캣 5.5에서는 Servlet 버전 2.4 제공.
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wannaqueen.gitbook.io/spring5/spring-5.0/1/1.15/1.15.4-by-sh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
