목차
Spring MVC Request Life Cycle - ViewResolver
- 핸들러 어뎁터 호출
- ViewResolver 호출
spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp
|
ViewResolver.java
public interface ViewResolver { @Nullable View resolveViewName(String viewName, Locale locale) throws Exception; }
|
스프링 부투에서는 InternalResourceViewResolver 를 등록할때 spring.mvc.view.prefix
, spring.mvc.view.suffix
설정 정보를 갖고와 등록해준다.
public InternalResourceViewResolver(String prefix, String suffix) { this(); setPrefix(prefix); setSuffix(suffix); }
|
InternalResourceViewResolver.java
public class InternalResourceViewResolver extends UrlBasedViewResolver {
private static final boolean jstlPresent = ClassUtils.isPresent("javax.servlet.jsp.jstl.core.Config", InternalResourceViewResolver.class.getClassLoader());
@Nullable private Boolean alwaysInclude;
public InternalResourceViewResolver() { Class<?> viewClass = requiredViewClass(); if (InternalResourceView.class == viewClass && jstlPresent) { viewClass = JstlView.class; } setViewClass(viewClass); }
public InternalResourceViewResolver(String prefix, String suffix) { this(); setPrefix(prefix); setSuffix(suffix); }
public void setAlwaysInclude(boolean alwaysInclude) { this.alwaysInclude = alwaysInclude; }
@Override protected Class<?> requiredViewClass() { return InternalResourceView.class; }
@Override protected AbstractUrlBasedView instantiateView() { return (getViewClass() == InternalResourceView.class ? new InternalResourceView() : (getViewClass() == JstlView.class ? new JstlView() : super.instantiateView())); }
@Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { InternalResourceView view = (InternalResourceView) super.buildView(viewName); if (this.alwaysInclude != null) { view.setAlwaysInclude(this.alwaysInclude); } view.setPreventDispatchLoop(true); return view; } }
|