プログラミング逆引き辞典

~ 多言語対応のプログラミングレシピ ~

SpringBoot エラーページ作成

①error.htmlの作成

エラー時に遷移するページ

・ファイル名:error.html
・格納先:src/main/resources/templates

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" th:href="@{/webjars/bootstrap/4.3.1/css/bootstrap.min.css}">
<title>エラー</title>
</head>
<body>
    <div class="container">
        <h1 class="mt-5" th:text="'status : ' + ${status}"></h1>
        <hr class="my-5">
        <h5 th:text="'error : ' + ${error}"></h5>
        <h5 th:text="'message : ' + ${message}"></h5>
        <hr class="my-5">
        <form th:aciton="@{/employee}" method="post">
            <input type="submit" class="btn btn-dark" value="戻る">
        </form>
    </div>
    <script th:src="@{/webjars/jquery/3.4.1/jquery.min.js}"></script>
    <script th:src="@{/webjars/bootstrap/4.3.1/js/bootstrap.min.js}"></script>
</body>
</html>

 
 


②application.propertiesに追記

ログをファイル出力する設定

・ファイル名:application.properties
・格納先:src/main/resources

#ログ出力
logging.level.root=INFO
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
logging.file.name=MyLog/myLog.log
logging.file.path=

 
 


③.gitignoreに追記(Git管理をしている場合)

ログフォルダ配下をGit管理から除去

        .
        .
        .
### STS ###
        .
        .
#ログフォルダを除去
.MyLog/*
        .
        .
        .