푸린세스

스프링MVC 기본구조 본문

spring/구멍가게코딩단-스프링

스프링MVC 기본구조

푸곰주 2023. 5. 2. 10:17

스프링MVC기본구조

 

-스프링MVC는 서브 프로젝트이다.

-스프링은 '코어'프레임워크에 여러 서브프로젝트를 결합해서 다양한 상황에 대처할 수 있도록 만들어진것.

-servlet-context.xml (MVC) +  root-context.xml (MyBatis, Core)

 

 

5.1 MVC프로젝트의 내부구조

 

스프링MVC프로젝트를 사용한다 

= root-context.xml (일반 자바영역, POJO) + servlet-context.xml (WEB관련 영역)

 

WebApplicationContext = 일반 설정 + MVC설정

 

 

5.2 예제 프로젝트릐 로딩구조

 

프로젝트 구동시 관여하는 XML = web.xml(Tomcat구동과 관련된 설정), root-context.xml, servlet-context.xml

 

구동시 web.xml에서부터 시작한다.

Context listener가 등록되어있다.

<context-param> :root-context.xml의 경로 설정

<listener> : 스프링MVC의 ContextLoaderListener가 등록

 

 

web.xml

5월 02, 2023 10:04:45 오전 org.apache.catalina.startup.Catalina load
INFO: [2667] 밀리초 내에 서버가 초기화되었습니다.
5월 02, 2023 10:04:46 오전 org.apache.catalina.core.StandardService startInternal
INFO: 서비스 [Catalina]을(를) 시작합니다.
5월 02, 2023 10:04:46 오전 org.apache.catalina.core.StandardEngine startInternal
INFO: 서버 엔진을 시작합니다: [Apache Tomcat/9.0.60]
5월 02, 2023 10:04:50 오전 org.apache.jasper.servlet.TldScanner scanJars
INFO: 적어도 하나의 JAR가 TLD들을 찾기 위해 스캔되었으나 아무 것도 찾지 못했습니다. 스캔했으나 TLD가 없는 JAR들의 전체 목록을 보시려면, 로그 레벨을 디버그 레벨로 설정하십시오. 스캔 과정에서 불필요한 JAR들을 건너뛰면, 시스템 시작 시간과 JSP 컴파일 시간을 단축시킬 수 있습니다.
5월 02, 2023 10:04:50 오전 org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
5월 02, 2023 10:04:50 오전 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue May 02 10:04:51 KST 2023]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 3524 ms
5월 02, 2023 10:04:54 오전 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
WARNING: [SHA1PRNG] 알고리즘을 사용하여, 세션 ID를 생성하기 위한 SecureRandom 객체를 생성하는데, [686] 밀리초가 소요됐습니다.
5월 02, 2023 10:04:55 오전 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue May 02 10:04:55 KST 2023]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET]}" onto public java.lang.String org.moominzero.controller.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue May 02 10:04:55 KST 2023]; parent: Root WebApplicationContext
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue May 02 10:04:55 KST 2023]; parent: Root WebApplicationContext
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 3815 ms
5월 02, 2023 10:04:58 오전 org.apache.coyote.AbstractProtocol start
INFO: 프로토콜 핸들러 ["http-nio-8080"]을(를) 시작합니다.
5월 02, 2023 10:04:59 오전 org.apache.catalina.startup.Catalina start
INFO: 서버가 [13450] 밀리초 내에 시작되었습니다.
INFO : org.moominzero.controller.HomeController - Welcome home! The client locale is ko_KR.
INFO : org.moominzero.controller.HomeController - Welcome home! The client locale is ko.
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/favicon.ico] in DispatcherServlet with name 'appServlet'

 

● ContextLoaderListener : 해당 웹 애플리케이션 구동시 같이 동작하므로 프로젝트 실행시 가장 먼저 로그를 출력하면서 기록된다.

 

INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]

 

 

● root-context.xml이 처리 되면 파일에 잇는 빈 설정들이 동작한다.

 

WebApplicationContext


root-context.xml에 정의된 Bean들 (스프링영역 context안에서 생성됨), + (의존성처리 된다.)

 

● 스프링MVC에서 사용하는 DispatcherServlet이라는 서블릿과 관련된 설정이 동작한다.

org.springframework.web.servlet.DispatcherServlet : 스프링MVC구조에서 가장 핵심적 역할을 하는 클래스

 

servlet-context.xml : 내부적으로 웹관련 처리준비작업 진행시 사용되는 파일

 

 

INFO: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue May 02 10:04:55 KST 2023]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET]}" onto public java.lang.String org.moominzero.controller.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue May 02 10:04:55 KST 2023]; parent: Root WebApplicationContext
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue May 02 10:04:55 KST 2023]; parent: Root WebApplicationContext
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 3815 ms

 

 

● DispatcherServlet에서 XmlWebApplicationContext를 이용하여 servlet-context.xml을 로딩하고 해석한다.

이과정에서 등록된 빈(객체)들은 기존에 만들어진 객체들과 같이 연동된다.

 

 

'spring > 구멍가게코딩단-스프링' 카테고리의 다른 글

p190 MySQL~Oracle  (0) 2023.05.03
스프링MVC의 기본사상  (0) 2023.05.02
MyBatis ~ 스프링과 연동처리  (0) 2023.05.01
커넥션 풀 설정  (0) 2023.05.01
구멍가게코딩단-스프링 p56  (0) 2023.05.01