<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<!--
  - DispatcherServlet application context for the Spring web MVC
  - implementation of JPetStore's web tier.
  -->

설명이 필요없다. 해석 그대로 Spring Web MVC용 DispatcherServlet application 컨텍스트라고 한다.

<beans>

 <!-- ========================= VIEW DEFINITIONS ========================= -->

VIEW영역을 JSP로 사용한다. JSP파일을 열어보니 JSTL을 사용하였다.
추후에 SITEMESH와 VELOCITY 그리고 STRUTS까지 연동해 볼 예정이다.

 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  <property name="prefix" value="/WEB-INF/jsp/spring/"/>
  <property name="suffix" value=".jsp"/>
 </bean>


 <!-- ========================= DEFINITIONS OF PUBLIC CONTROLLERS ========================= -->

HandlerMapping에는 두가지가 있다. BeanNameUrlHandlerMapping과  SimpleUrlHandlerMapping 이다.
이 부분은 첫번째의 BeanNameUrlHandlerMapping을 이용하여 HandlerMapping을 처리하는 부분이다.
보다 자세한 내용은
여기 를 참조하기 바란다.

 <bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

 <bean name="/shop/addItemToCart.do" class="org.springframework.samples.jpetstore.web.spring.AddItemToCartController">
  <property name="petStore" ref="petStore"/>
 </bean>

bean태그의 name속성은 실제 브라우저의 url에 해당한다. 그리고 해당 url의 요청을 class속성에 정의된 Controller로 연결해 준다.
Controller클래스에서는 property태그에 정의된 name과 value등으로 파라미터를 전해 받는다.

 <bean name="/shop/checkout.do" class="org.springframework.samples.jpetstore.web.spring.ViewCartController">
  <property name="successView" value="Checkout"/>
 </bean>

 <bean name="/shop/index.do" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
  <property name="viewName" value="index"/>
 </bean>

 <bean name="/shop/newAccount.do" class="org.springframework.samples.jpetstore.web.spring.AccountFormController">
  <property name="petStore" ref="petStore"/>
  <property name="validator" ref="accountValidator"/>
  <property name="successView" value="index"/>
 </bean>

 <bean name="/shop/removeItemFromCart.do" class="org.springframework.samples.jpetstore.web.spring.RemoveItemFromCartController"/>

 <bean name="/shop/signoff.do" class="org.springframework.samples.jpetstore.web.spring.SignoffController"/>

 <bean name="/shop/searchProducts.do" class="org.springframework.samples.jpetstore.web.spring.SearchProductsController">
  <property name="petStore" ref="petStore"/>
 </bean>

 <bean name="/shop/signon.do" class="org.springframework.samples.jpetstore.web.spring.SignonController">
  <property name="petStore" ref="petStore"/>
 </bean>

 <bean name="/shop/signonForm.do" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
  <property name="viewName" value="SignonForm"/>
 </bean>

 <bean name="/shop/updateCartQuantities.do" class="org.springframework.samples.jpetstore.web.spring.UpdateCartQuantitiesController"/>

 <bean name="/shop/viewCart.do" class="org.springframework.samples.jpetstore.web.spring.ViewCartController">
  <property name="successView" value="Cart"/>
 </bean>

 <bean name="/shop/viewCategory.do" class="org.springframework.samples.jpetstore.web.spring.ViewCategoryController">
  <property name="petStore" ref="petStore"/>
 </bean>

 <bean name="/shop/viewItem.do" class="org.springframework.samples.jpetstore.web.spring.ViewItemController">
  <property name="petStore" ref="petStore"/>
 </bean>

 <bean name="/shop/viewProduct.do" class="org.springframework.samples.jpetstore.web.spring.ViewProductController">
  <property name="petStore" ref="petStore"/>
 </bean>


 <!-- ========================= DEFINITIONS OF PROTECTED CONTROLLERS ========================= -->

SimpleUrlHandlerMapping는 BeanNameUrlHandlerMapping에 비해 보다 강력한 기능을 제공하므로 설정하는 변수들 또한 복잡해 보인다.

 <bean id="secureHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="interceptors">
   <list>
    <ref bean="signonInterceptor"/>
   </list>
  </property>

interceptors프로퍼티는 요청url이 Controller에게 제어가 넘겨지기 전에 수행되는 부분이다.

  <property name="urlMap">
   <map>
    <entry key="/shop/editAccount.do" value-ref="secure_editAccount"/>
    <entry key="/shop/listOrders.do" value-ref="secure_listOrders"/>
    <entry key="/shop/newOrder.do" value-ref="secure_newOrder"/>
    <entry key="/shop/viewOrder.do" value-ref="secure_viewOrder"/>
   </map>
  </property>

urlMap프로퍼티는 요청url을 Controller와 연결하는 역활을 한다.
key가 요청url이고 value-ref가 실행될 Controller를 나타낸다.
value-ref에 정의된 Controller들은 하단부에 정의되어 있다.

 </bean>

 <bean id="signonInterceptor" class="org.springframework.samples.jpetstore.web.spring.SignonInterceptor"/>

SignonInterceptor.java 클래스를 열어보았지만 주석이 한줄도 없다.
단지 코드를 보면 userSession이 있는지 없는지에 따라 로그인 상태 여부를 검사하고 있다.

http://openframework.or.kr/framework_reference/spring/ver2.x/html/mvc.html#mvc-handlermapping-interceptor
여기서 HandlerInterceptor인터페이스의 쓰임새를 공부하자.

 <bean id="secure_editAccount" class="org.springframework.samples.jpetstore.web.spring.AccountFormController">
  <property name="petStore" ref="petStore"/>
  <property name="validator" ref="accountValidator"/>
  <property name="successView" value="index"/>
 </bean>

 <bean id="secure_listOrders" class="org.springframework.samples.jpetstore.web.spring.ListOrdersController">
  <property name="petStore" ref="petStore"/>
 </bean>

 <bean id="secure_newOrder" class="org.springframework.samples.jpetstore.web.spring.OrderFormController">
  <property name="petStore" ref="petStore"/>
  <property name="validator" ref="orderValidator"/>
 </bean>

 <bean id="secure_viewOrder" class="org.springframework.samples.jpetstore.web.spring.ViewOrderController">
  <property name="petStore" ref="petStore"/>
 </bean>

</beans>

번호 제목 글쓴이 날짜 조회 수
공지 [작성중/인프런] 스프링부트 시큐리티 & JWT 강의 황제낙엽 2023.12.20 5083
84 @ConfigurationProperties 사용하기 황제낙엽 2025.10.23 1617
83 Spring Boot 에서 서버 로직의 역할별 애노테이션 구분 황제낙엽 2025.10.13 1411
82 (확인전) [2021.03.12] Eclipse에서 Spring Boot로 JSP사용하기(Gradle) file 황제낙엽 2023.12.23 2817
81 Spring Boot PetClinic Sample Application 황제낙엽 2023.12.21 2575
80 Eclipse, Spring Boot, Gradle, SVN 레거시(2019) 시스템 유지보수 환경 구축 file 황제낙엽 2023.11.14 1732
79 [시리즈 강좌] 스프링부트로 웹서비스 구축하기 황제낙엽 2023.07.13 1691
78 Spring Boot에서의 RESTful API 모듈 file 황제낙엽 2020.04.16 1896
77 [POST] Spring MVC 구조 분석 황제낙엽 2024.01.17 2053
76 Spring Framework 에서 사용하는 annotation 황제낙엽 2024.01.17 2093
75 Spring MVC configuration file 황제낙엽 2024.01.17 2041
74 [스프링 시큐리티 OAuth2] 강의 자료와 학습용 소스 file 황제낙엽 2024.01.15 1595
73 OAuth 2.0 Resource Server - Spring Security OAuth2.0 황제낙엽 2023.12.27 2016
72 Spring, JSP, Gradle, Eclipse 환경 구축[2] - 샘플 프로젝트 file 황제낙엽 2023.12.24 1922
71 Spring, JSP, Gradle, Eclipse 환경 구축[1] - 레퍼런스 조사 황제낙엽 2023.12.23 2056
70 spring-security-samples 황제낙엽 2023.12.22 1800
69 [Bard] Spring 과 Spring Boot의 차이 file 황제낙엽 2023.12.21 1803
68 Spring 과 Spring Boot의 차이 file 황제낙엽 2020.05.26 2308
67 Spring Security OAuth2.0 파헤치기 황제낙엽 2019.09.05 2079
66 Spring Security OAuth2구현 file 황제낙엽 2019.09.05 2208
65 Spring Security OAuth 황제낙엽 2019.09.05 2442