spring-boot: Suppress "Circular view path [error]" error message
- clone simple project: https://github.com/stepancheg/spring-boot-whitelabel
project contains controller with function
@RequestMapping("/throw")
@ResponseBody
public String t() {
throw new RuntimeException();
}
and project calls
System.setProperty("error.whitelabel.enabled", "false");
before main.
- run main class (demo.Application)
- point browser to http://localhost:8080/throw
Browser displays white page. Expecting something more sensible. Tomcat default error handler would be perfect.
Using spring-boot 1.2.0.RC2.
About this issue
- Original URL
- State: open
- Created 12 years ago
- Comments: 18 (8 by maintainers)
@wilkinsona Sorry to dig up an old issue. But we have been seeing the same thing in our setup. I suppose it is a bit of a niche issue, since not many people actually turn off the default whitelabel behaviour, or just implement their own error view right away.
Much like the original issue report we have
server.error.whitelabel.enabled=falseand a@Controllerthrowing aRuntimeException. This is with spring-boot 1.5.19 and embedded tomcat container.On the frontend, you will indeed get a normal Tomcat error page. In the backend a nasty error will be logged.
javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)This is a majorly confusing error, although the documentation (https://docs.spring.io/spring-boot/docs/1.5.19.RELEASE/reference/html/howto-actuator.html) seems correct in mentioning that:
It is
ErrorPageCustomizerinErrorMvcAutoConfigurationthat actually registers anErrorPageeven thoughserver.error.whitelabel.enabledis set tofalse.In my opinion, registering the
ErrorPageat that point should not be done by default, but maybe made optional. It feels as if two autoconfiguration things have been mixed, which leads to a confusing error being logged in the end.server.error.register-default-error-page), by defaulttrueto keep backwards compatibility? Which allows turning off the registration ofErrorPage.WhitelabelErrorViewConfigurationwouldn’t have been handled, but could exist if you have defined your own error view.ErrorPageCustomizer@ConditionalOnMissingBean? So you can define your own empty implementation?At the moment I use a hacky
BeanPostProcessorto achieve the “wanted” behaviour (code for spring boot 2).Of course using
achieves the same.
The behaviour is also still present in Spring Boot 2.1.3.RELEASE so a fix for the confusing error message might still be needed. All configuration changes seem like a bit of a hack for fixing a confusing error message.
If you’d like a test project, I have one available to upload right away.
Thoughts?
2024, and still facing the problem with a controller throwing an exception in an application where whitelabel error pages are disabled. Adding
@EnableAutoConfiguration(exclude= ErrorMvcAutoConfiguration.class)resolves the issue, but this really should be handled in Spring to achieve the principle of least surprise. I expect to see a stack of the exception that caused a 500 response in my API, not a bunch of stack traces forCircular view path error.