Issue
I have a SpringBoot v2.3.7.RELEASE with Thymeleaf. I've created this template to see the Errors, but I don't see any exceptions in the source code when there is an exception in the app:
<div class="jumbotron text-center">
<h1>Uh-oh! Something Happened!</h1>
<!-- As we are using Thymeleaf, you might consider using
${#httpServletRequest.requestURL}. But that returns the path
to this error page. Hence we explicitly add the url to the
Model in some of the example code. -->
<p th:if="${url}">
<b>Page:</b> <span th:text="${url}">Page URL</span>
</p>
<p th:if="${timestamp}" id='created'>
<b>Occurred:</b> <span th:text="${timestamp}">Timestamp</span>
</p>
<p>Support may ask you to right click to view page source.</p>
<!--
// Hidden Exception Details - this is not a recommendation, but here is
// how you hide an exception in the page using Thymeleaf
-->
<div th:utext="'<!--'" th:remove="tag"></div>
<div th:utext="'Failed URL: ' + ${url}" th:remove="tag">${url}</div>
<div th:utext="'Exception: ' + ${exception}" th:remove="tag">${exception}</div>
<ul th:remove="tag">
<li th:each="ste : ${exception}" th:remove="tag"><span
th:utext="${ste}" th:remove="tag">${ste}</span></li>
</ul>
<div th:utext="'-->'" th:remove="tag"></div>
</div>
</div>
and the controller:
@Controller
public class MyErrorController implements ErrorController {
private final static String PATH = "/error";
@RequestMapping(PATH)
public String getErrorPath() {
return "error/genericError";
}
}
Solution
Spring Boot by default provides /error mapping where all exception/errors are forwarded. In case of Thymeleaf (or other template engines), we can map errors to a global custom template file by name 'error' under src/main/resources/templates/ directory.
enable the stacktrace to be included as expression attribute to the Thymeleaf view:
server.error.include-stacktrace=always
Answered By - en Peris