Spring MVC에 대한 Java 기반 구성을 사용자 정의하기위한 콜백 메소드를 정의합니다
@Configuration
@ComponentScan
@EnableWebMvc
public class WebConfig {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/WEB-INF/");
internalResourceViewResolver.setSuffix(".jsp");
return internalResourceViewResolver;
}
}
여기서 WebMvcComfigurer를 implements 한다면 위 처럼 ViewResolver를 일일이 Bean으로 등록할 필요없이 손쉽게 EnableWebMvc 등록한 ViewResolver를 커스터마이징하면서 사용할 수 있습니다.
@Configuration
@ComponentScan
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/",".jsp");
}
}