헤르메스 LIFE

Could not resolve view with name 'index' in servlet with name 'dispatcherServlet' 본문

Exception

Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

헤르메스의날개 2021. 7. 28. 23:33
728x90

Interceptor를 등록 후 아래와 같은 오류가 발생하였습니다.

 

Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

package com.study.myweb.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// Spring MVC 프로젝트에 관련된 설정을 하는 클래스
@Configuration
//@EnableWebMvc
public class WebMVCConfig implements WebMvcConfigurer {
    @Autowired
    @Qualifier( value = "authInterceptor" )
    private HandlerInterceptor authInterceptor;

	/**
	 * Interceptor 를 등록
	 */
	@Override
    public void addInterceptors( InterceptorRegistry registry ) {
        registry.addInterceptor( authInterceptor ).addPathPatterns( "/**" );
    }

}

문제는 @EnableWebMvc 가 원인이였습니다.

the Spring Boot Reference Guide:
27.1.1 Spring MVC Auto-configuration
If you want to keep Spring Boot MVC features and you want to add additional MVC configuration [...] you can add your own @Configuration class of type WebMvcConfigurer but without @EnableWebMvc.
If you want to take complete control of Spring MVC, you can add your own @Configuration annotated with @EnableWebMvc.

Spring Boot MVC 기능을 유지하고, 추가 MVC 구성[...]을(를) 추가하려면 
WebMvcConfigurer 유형의 고유한 @Configuration 클래스는 추가할 수 있지만 
@EnableWebMvc는 추가할 수 없습니다.

Spring Boot 의 고유기능을 사용하기 위해서는 @EnableWebMvc 는 사용하지 않습니다.

@EnableWebMvc를 사용하면 Spring MVC를 사용하게 되어 직접 MVC 설정을 해주어야 한다는 의미입니다.


참고

https://stackoverflow.com/questions/51303453/spring-boot-could-not-resolve-view-with-name-index-in-servlet-with-name-disp

 

Spring Boot: Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

I am trying to set home page of my application by using spring boot.. but I am getting the error as Could not resolve view with name 'index.html' in servlet with name 'dispatcherServlet' My code i...

stackoverflow.com

 

728x90