2017-12-04 5 views
0

Heroku에 내 Spring App을 성공적으로 전개했으나, 실제로 작동중인 응용 프로그램을 테스트하려고 시도 할 때 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 파일에 대한 링크, 부트 스트랩과 하나가 포함되어 내 자신의 수정 프로그램. 로컬에서는 모든 것이 정상적으로 작동합니다. 모든보기가 완벽하게로드됩니다. 페이지를로드하고 CSS를 적용하는 데 걸리는 시간이 0.5 초 밖에되지 않지만 heroku에서는 괜찮을 것으로 생각합니다.

내 ASPP이 링크에서 볼 수 있습니다 : 내 응용 프로그램의 https://spring-personal-blog.herokuapp.com

또한 전체 코드는 GitHub의에 repository에서 사용할 수 있습니다.

답변

1
  1. th:replace 구문이 잘못되었습니다. 당신 <head> 내부 템플릿

  2. <div>의 모든 다른 조각에 대한

    th:replace="fragments/head :: head" 
    // or 
    th:replace="fragments/head" // instead of th:replace="/fragments/head" 
    
    th:replace="directory/filename :: fragmentName" 
    

    와 유사한 변화를 사용하는 경우, 당신은 아마 th:remove="tag"를 사용해야합니다.

    //home.html 
    <div th:replace="fragments/head :: head" th:remove="tag"></div> 
    
    //fragments/head.html 
    <head th:fragment="head">...</head> 
    

PS. 나는 당신의 github 프로젝트와 놀았는데, 당신의 표기법이 실제로 localhost에서 작동하지만 heroku를 깨뜨리는 것은 다소 이상합니다. 그리고 위의 수정은 영웅에 대한 저를 위해 그것을 해결했습니다 DEMO. Btw 또한 다른 설정 파일에 passwordEncoder bean을 넣어야했습니다. 그렇지 않으면 heroku에서 시작할 수 없었습니다.

+0

두 번째로 동일한 heroku 저장소에 내 응용 프로그램을 다시 배포하면 circualr 참조로 인해 오류가 발생합니다. PasswordEncoder. 나는 이유를 모른다. 지역적으로 모든 것이 잘 작동합니다. – Gromo

+0

귀하의 게시물을 한 번 더 읽고 PasswordEncoder 구성을 별도의 파일로 옮겼습니다. 모든 것이 잘 작동합니다. 컨트롤러의 모든 view-name 문자열 앞에'/'에 약간의 문제가 있었지만 잠시 후에 고칠 수있었습니다. 한 번 더 도움을 주셔서 대단히 감사합니다. – Gromo

관련 문제