錯誤描述:

Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Tue Mar 2822:25:43 CST 2017There was an unexpected error (type=Internal Server Error, status=500).Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

在測試過程中我用bean嘗試過注入:



import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;


public class WebConfig  extends WebMvcConfigurerAdapter{
//配置jsp檢視解析器
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver=new InternalResourceViewResolver();
resolver.setPrefix("/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
這兩個地方,在springboot的區別中,早期的版本中是不帶mvc的,在1.0的配置中是需要帶mvc的(特殊錯誤,需要特別記憶)
#spring.view.prefix=/views/
#spring.view.suffix=.jsp
#spring.mvc.view.prefix=/views/
#spring.mvc.view.suffix=.jsp
}

解決方案:在application.properties檔案中正確配置模板檔案的命名前後綴:

#spring.mvc.view.prefix=/views/
#spring.mvc.view.suffix=.jsp

另外,在早期版本的springboot中,這個key中是不帶mvc的:

#spring.view.prefix=/views/
#spring.view.suffix=.jsp

這個配置類是1.1版本之後的,在org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties類中。上面的註解@ConfigurationProperties(prefix = "spring.mvc")指明瞭這個key