> For the complete documentation index, see [llms.txt](https://wannaqueen.gitbook.io/spring5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wannaqueen.gitbook.io/spring5/spring-5.0/1/1.15/1.15.4-applicationcontext.md).

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

예를 들어서 ContextLoader와 같이 선언적으로 ApplicationContext를 생성할 수 있다. 물론 ApplicationContext 인스턴스를 ApplicationContext 확장체 중의 하나로서 프로그래밍적으로 생성할 수 있다.

아래 예제처럼 ContextLoaderListener 를 사용해서 ApplicationContext를 등록할 수 있다.

> ```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을 기본적으로 사용한다. 파라미터가 존재하지 않으면 리스너는 String을 (콤마, 스미콜론, 공백) 딜리미터로 분리하고 application context들이 찾은 위치의 값을 사용한다. Ant-style 경로 패턴은 잘 지원된다. 예제들은 /WEB-INF/\*Context.xml(Context.xml로 끝나는 모든 파일들과 WEB-INF 디렉토리에 있는 것들) 과 /WEB-INF/\*\*/\*Context.xml(WEB0INF의 서브디렉토리에 있는 모든 파일들)이다.

{% hint style="info" %}
Ant-style

\*,\*\*,?의 표현식을 사용하는 패턴

참조 : <https://lng1982.tistory.com/169>

? : 1개의 문자와 매칭 (matches single character)

\* : 0개 이상의 문자와 매칭 (matches zero or more characters)

\*\* : 0개 이상의 디렉토리와 파일 매칭 (matches all files / directories)
{% endhint %}
