eleaf+springboot:在错误页面中显示错误

yb3bgrhw  于 2021-06-29  发布在  Java
关注(0)|答案(2)|浏览(291)

我有一个springbootv2.3.7.release和thymeleaf。我创建此模板是为了查看错误,但当应用程序中出现异常时,在源代码中看不到任何异常:

<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="'&lt;!--'" 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="'--&gt;'" th:remove="tag"></div>

    </div>

</div>

以及控制器:

@Controller
public class MyErrorController implements ErrorController {

    private final static String PATH = "/error";

    @RequestMapping(PATH)
    public String getErrorPath() {
        return "error/genericError";
    }

}
camsedfj

camsedfj1#

在你的 application.properties ,必须禁用 whitelabel 错误页面如下

server.error.whitelabel.enabled=false
u91tlkcl

u91tlkcl2#

默认情况下,spring引导提供了所有异常/错误的转发/错误Map。对于thymeleaf(或其他模板引擎),我们可以将错误Map到src/main/resources/templates/目录下的全局自定义模板文件。
启用stacktrace作为expression属性包含到thymeleaf视图中:
server.error.include stacktrace=始终

相关问题