-
web.xml 에 선언된 context-param, init-param 테스트Spring 2021. 6. 30. 00:41
실제작성일 2018년 12월 13일
web.xml
metawerx 사이트 를 참고 했습니다.
context-param
<context-param>
태그는 전체context/web application
에parameter
를 제공합니다.실제 테스트를 해봤습니다.
web.xml
코드<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/application-config.xml</param-value> </context-param>
spring
Controller
에서 테스트 해봤습니다.@RequestMapping("/test") public String test(HttpServletRequest request) { String initParameter = request.getServletContext().getInitParameter("contextConfigLocation"); LOG.debug("contextConfigLocation ::: {}", initParameter); return "test"; }
아래는
ouput
입니다.DEBUG: contextConfigLocation ::: classpath:spring/application-config.xml
web.xml
설정에context-param
으로 지정한 값이 출력 됐습니다.init-param
<init-param>
태그는 단일servlet
또는filter
에parameter
를 제공합니다.<param-name>
은parameter
명 입니다.<param-value>
는 값 입니다.실제 테스트 입니다.
<servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-web-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
동일하게
spring Controller
에서 테스트 했습니다.@Autowired private ServletConfig servletConfig; @RequestMapping("/test") public String test(HttpServletRequest request) { String servletInitParam = servletConfig.getInitParameter("contextConfigLocation"); LOG.debug("servletInitParam ::: {}", servletInitParam); return "test"; }
output
입니다.DEBUG: servletInitParam ::: /WEB-INF/mvc-web-config.xml
'Spring' 카테고리의 다른 글
프로젝트 회고 - 수업 스케줄 일괄 변경 배치 처리 (0) 2024.04.08 프로젝트 회고 - 스케줄 자동 공개 성능 최적화 (1) 2024.04.04 Spring Version에 맞는 h2Database 설치 (0) 2023.04.16 @Transactional 제대로 알고 쓰기 (0) 2021.11.18 @ConfigurationProperties 사용해보기 (0) 2021.05.18