<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/context-*.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
설정파일을 보게되면 ApplicationContext와 WebApplicationContext 두 부분에 대한 내용을 확인 할 수 있다.
ApplicationContext는 ContextLoaderListener 클래스에 의해 만들어지고, WebApplicationContext는 DispatcherSerlvet 클래스에 의해 만들어진다.
ApplicationContext와 WebApplicationContext의 관계를 도식화 한 자료이다.
<context:component-scan base-package="패키지경로">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
component-scan의 설정을 통해 Service, DAO를 Bean으로 등록해준다.
<context:component-scan base-package="패키지경로">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
component-scan의 설정을 통해 Controller를 Bean으로 등록해준다.
context란?
- Spring이 관리하는 bean들이 담겨있는 컨테이너를 말한다.
REST API 개념 (0) | 2022.07.13 |
---|---|
annotation-driven / component-scan / annotation-config 차이 정리 (1) | 2022.03.28 |
[JAVA] Multi-Thread 사용법 (0) | 2022.03.02 |
[Spring] IoC 컨테이너 / Bean (0) | 2021.10.14 |
Spring AOP (Proxy) - Logging 적용 (0) | 2021.10.08 |
댓글 영역