私はHerokuにSpringアプリケーションを正常にデプロイしましたが、実際にアプリケーションをテストしようとすると、 Error resolving template "/fragments/head.html", template might not exist or might not be accessible by any of the configured Template Resolvers (home:4)
エラーが発生します。 ローカルで私のアプリが問題なく正常に動作するので、奇妙です。Herokuは私のフラグメントを表示しません
Home.htmlコード:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<div th:replace="/fragments/head.html"></div>
<title>Personal blog - Home</title>
</head>
<body>
<div class="container">
<div th:replace="/fragments/header" th:class="row"> </div>
<div class="container">
<div class="container border w-100 post" th:each="post : ${posts}">
<div class="container">
<h1 class="display-5">
<a th:href="@{/post/} + ${post.id}" th:text="${post.title}"></a>
</h1>
<small class="text-muted" th:text="${post.creationDate}"></small>
</div>
<div class="container">
<p class="lead text-justify" th:text="${post.contents}"></p>
</div>
</div>
<nav>
<ul class="pagination justify-content-center" th:if="${lastPageIndex} gt 1">
<li class="page-item">
<a class="page-link"
th:if="${currentPage gt 1}"
th:href="@{/home/} + ${currentPage-1}">Previous</a>
</li>
<li class="page-item">
<a class="page-link" th:if="${currentPage-3} ge 1"
th:href="@{/home/} + ${currentPage-3}"
th:text="${currentPage-3}"></a>
</li>
<li class="page-item">
<a class="page-link"
th:if="${currentPage-2} ge 1"
th:href="@{/home/} + ${currentPage-2}"
th:text="${currentPage-2}"></a>
</li>
<li class="page-item">
<a class="page-link"
th:if="${currentPage-1} ge 1"
th:href="@{/home/} + ${currentPage-1}"
th:text="${currentPage-1}"></a>
</li>
<li class="page-item">
<a class="page-link" th:text="${currentPage}"></a>
</li>
<li class="page-item">
<a class="page-link"
th:if="${currentPage+1} le ${lastPageIndex}"
th:href="@{/home/} + ${currentPage+1}"
th:text="${currentPage+1}"></a>
</li>
<li class="page-item">
<a class="page-link"
th:if="${currentPage+2} le ${lastPageIndex}"
th:href="@{/home/} + ${currentPage+2}"
th:text="${currentPage+2}"></a>
</li>
<li class="page-item">
<a class="page-link"
th:if="${currentPage+3} le ${lastPageIndex}"
th:href="@{/home/} + ${currentPage+3}"
th:text="${currentPage+3}"></a>
</li>
<li class="page-item">
<a class="page-link"
th:if="${currentPage} lt ${lastPageIndex}"
th:href="@{/home/} + ${currentPage+1}">Next</a>
</li>
</ul>
</nav>
</div>
<div th:replace="/fragments/footer"> </div>
</div>
</body>
</html>
Head.htmlコード:
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org">
<head>
<div th:fragment="head">
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"
integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"
crossorigin="anonymous"/>
</div>
</head>
</html>
あなたが見ることができるように、私のHead.htmlは私と二CSSファイル、ブートストラップ付き1へのリンクが含まれています自分の修正。ローカルでは、すべて正常に動作します。すべてのビューが完璧にロードされています。ページを読み込んでCSSを適用するまでには、ちょっとだけの時間差がありますが、ヒロクではうまくいくと思います。
私のASPPは、このリンクの下で提供されています:私のアプリのhttps://spring-personal-blog.herokuapp.com
また、全体のコードは、githubの上repositoryで利用可能です。
2回目の同じherokuリポジトリにアプリケーションを再デプロイすると、 PasswordEncoder。何故かはわからない。ローカルではすべて正常に動作します。 – Gromo
あなたの投稿をもう一度読んで、PasswordEncoder設定を別のファイルに移動しました。すべてうまく動作します。コントローラ内の各ビュー名文字列の前には '/'の問題はほとんどありませんでしたが、1分で修正しました。 もう一度ご協力いただきありがとうございます。 – Gromo