13.2 Spring Boot启动报错:Whitelabel Error Page

简介: 13.2 Spring Boot启动报错:Whitelabel Error Page问题描述Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.

13.2 Spring Boot启动报错:Whitelabel Error Page

问题描述

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Mar 28 22:25:43 CST 2017
There 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.)

原因分析

首先,这个出错页面是SpringBoot的一个默认出错页面。源码在:org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration 第151行。

这种错误一般是配置错误,或者MVC报错引起的错误。

解决方案

在application.properties 文件中正确配置模板文件的命名前后缀:

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

另外,在早期版本的springboot中,这个key中是不带mvc的。

spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp

这个配置类是1.1版本之后的,在org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties类中。上面的注解@ConfigurationProperties(prefix = "spring.mvc")指明了这个key。

相应的,模板文件要放在正确的目录下。上面的配置,对应的目录可以是:

/src/main/webapp/WEB-INF/jsp/
/src/main/resources/META-INF/resources/WEB-INF/jsp

SpringBoot常见的模板文件默认目录,举例如下:

# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.cache=true # Enable template caching.
spring.thymeleaf.check-template=true # Check that the template exists before rendering it.
spring.thymeleaf.check-template-location=true # Check that the templates location exists.
spring.thymeleaf.enabled=true # Enable Thymeleaf view resolution for Web frameworks.
spring.thymeleaf.encoding=UTF-8 # Template files encoding.
spring.thymeleaf.excluded-view-names= # Comma-separated list of view names that should be excluded from resolution.
spring.thymeleaf.mode=HTML5 # Template mode to be applied to templates. See also StandardTemplateModeHandlers.
spring.thymeleaf.prefix=classpath:/templates/ # Prefix that gets prepended to view names when building a URL.
spring.thymeleaf.reactive.max-chunk-size= # Maximum size of data buffers used for writing to the response, in bytes.
spring.thymeleaf.reactive.media-types=text/html # Media types supported by the view technology.
spring.thymeleaf.servlet.content-type=text/html # Content-Type value written to HTTP responses.
spring.thymeleaf.suffix=.html # Suffix that gets appended to view names when building a URL.
spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain.
spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.


# FREEMARKER (FreeMarkerAutoConfiguration)
spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.allow-session-override=false # Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.cache=false # Enable template caching.
spring.freemarker.charset=UTF-8 # Template encoding.
spring.freemarker.check-template-location=true # Check that the templates location exists.
spring.freemarker.content-type=text/html # Content-Type value.
spring.freemarker.enabled=true # Enable MVC view resolution for this technology.
spring.freemarker.expose-request-attributes=false # Set whether all request attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-spring-macro-helpers=true # Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
spring.freemarker.prefer-file-system-access=true # Prefer file system access for template loading. File system access enables hot detection of template changes.
spring.freemarker.prefix= # Prefix that gets prepended to view names when building a URL.
spring.freemarker.request-context-attribute= # Name of the RequestContext attribute for all views.
spring.freemarker.settings.*= # Well-known FreeMarker keys which will be passed to FreeMarker's Configuration.
spring.freemarker.suffix= # Suffix that gets appended to view names when building a URL.
spring.freemarker.template-loader-path=classpath:/templates/ # Comma-separated list of template paths.
spring.freemarker.view-names= # White list of view names that can be resolved.

# GROOVY TEMPLATES (GroovyTemplateAutoConfiguration)
spring.groovy.template.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.groovy.template.allow-session-override=false # Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.groovy.template.cache= # Enable template caching.
spring.groovy.template.charset=UTF-8 # Template encoding.
spring.groovy.template.check-template-location=true # Check that the templates location exists.
spring.groovy.template.configuration.*= # See GroovyMarkupConfigurer
spring.groovy.template.content-type=test/html # Content-Type value.
spring.groovy.template.enabled=true # Enable MVC view resolution for this technology.
spring.groovy.template.expose-request-attributes=false # Set whether all request attributes should be added to the model prior to merging with the template.
spring.groovy.template.expose-session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template.
spring.groovy.template.expose-spring-macro-helpers=true # Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
spring.groovy.template.prefix= # Prefix that gets prepended to view names when building a URL.
spring.groovy.template.request-context-attribute= # Name of the RequestContext attribute for all views.
spring.groovy.template.resource-loader-path=classpath:/templates/ # Template path.
spring.groovy.template.suffix=.tpl # Suffix that gets appended to view names when building a URL.
spring.groovy.template.view-names= # White list of view names that can be resolved.


相关文章
|
1月前
|
Java
SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
40 0
|
1月前
|
Java
SpringBoot启动报错org.apache.catalina.LifecycleException
SpringBoot启动报错org.apache.catalina.LifecycleException
17 0
|
1月前
|
监控 Java API
Spring cloud Hystrix 、Dashboard、API(zuul)相关报错
Spring cloud Hystrix 、Dashboard、API(zuul)相关报错
29 2
|
2天前
|
Java 关系型数据库 MySQL
【已解决】SpringBoot 启动报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no emb
【已解决】SpringBoot 启动报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no emb
10 0
|
3天前
|
Java
SpringBoot启动报错:Unable to start LiveReload server【已解决】
SpringBoot启动报错:Unable to start LiveReload server【已解决】
8 0
|
9天前
|
Java Spring
解决Springboot集成ElasticSearch 报错:A bean with that name has already been defined in null and overriding
解决Springboot集成ElasticSearch 报错:A bean with that name has already been defined in null and overriding
|
11天前
spring-boot报错循环注入报错:has been injected into other beans
spring-boot报错循环注入报错:has been injected into other beans
|
1月前
|
Java 测试技术 Maven
Spring Boot单元测试报错java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]
Spring Boot单元测试报错java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]
|
1月前
|
Java 数据库连接 Spring
【SpringBoot】Error starting ApplicationContext. To display the conditions report re--run your app
【SpringBoot】Error starting ApplicationContext. To display the conditions report re--run your app
122 0
|
1月前
|
安全 Java 应用服务中间件
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
38 0
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置