[오류해결]template might not exist or might not be accessible by any of the configured Template Resolvers

2022. 7. 7. 18:53·📂 Troubleshooting & Ops
728x90
반응형

뷰에서 해당 게시글 삭제를 만들려고 하던 중 맞이한 오류이며 JPA queryDsl 작성중 맞이한 오류이다.

뷰 페이지에서 게시글 삭제 버튼 클릭 시 ajax를 통해 해당 게시글의 id를 보내주고, 

Controller에서 @Pathvariable로 id값을 받아서 DaoCustom, DaoCustomImpl로 가는 로직을 구상했다. 

 

그러던 중 아래와 같은 오류 메시지를 마주했다.

template might not exist or might not be accessible by any of the configured Template Resolvers

원인을 구글링해 본 결과 리턴해 줄 페이지가 없을 경우 경로를 찾지 못해 발생한 오류 라고 한다.

 

그러나 나는 @DeleteMapping을 사용하므로 리턴 페이지가 필요 없었고

페이지를 그릴 필요가 없는데 왜 오류가 나는 것이지??  라는 생각을 했다.

 

그러던 중 해결하게 되어 아래에 글을 작성하게 되었다.

 

1. 전체 로직을 살펴보자.


Q. 오류가 났을 때 내가 집중적으로 봤던 부분들이다. 이 말이 오류를 해결할 수 있는 힌트다.

write.html

//ajax 임시저장 삭제 로직 
function deleteDraftArticle(targetId) {
   if(!confirm("정말로 삭제하시겠습니까?")) {
      alert("취소되었습니다.");
   } else{$.ajax({
      url: "/v1/delete/" + targetId,
      method: "DELETE",
      success: function (result) {
         console.log("result", result);
         alert("삭제되었습니다.");
         reloadDraftArticles();
      },
      error: function(xhr, status, error) {
         var response = JSON.parse(xhr.responseText);
         if(response) {
            alert("요청 실패");
         }else {
            alert("API 호출 실패");
         }
      }
   });
   }
}

Controller

@DeleteMapping("/delete/{articleId}")
public void deleteDraftArticle(HttpServletRequest req, @PathVariable("articleId") Long articleId) {
   articleDao.deleteArticleById(articleId);
}

DaoCustom

void deleteArticleById(Long articleId);

DaoCustomImpl

@Override
@Transactional
public void deleteArticleById(Long articleId) {
   queryFactory.delete(bookClubArticle)
         .where(article.id.eq(articleId)
               .and(article.status.eq(ArticleStatus.WRITE)))
         .execute();
}

2. 문제해결


@Controller와 @RestController

Q. 오류가 났을 때 내가 집중적으로 봤던 부분들이다. 
위에 작성한 부분을 기억하는가? 

해답은 바로 @RestController가 아닌 @Controller로 선언된 Controller에서 작업했기 때문이다.


내가 이런 실수를 한 이유는

 

1. 나는 그동안 다뤘던 코드의 부분들은 다 @RestController가 선언된 파일들이였기 때문에 

당연히 이번에도 @RestController인 줄 알았다...

2. Controller를 만든 파일명이 article에 대해 선언된 Controller라 해당 파일에 만들면 될 줄 알았음 

 

즉 나의 경우는 @RestController에 선언된 곳에서 작업을 하지 않았기 때문에 발생한 오류 였다.

 

 

[@Controller가 아닌 @RestController의 차이]

@RestController는 이름에서도 알 수 있겠지만 

RestAPI를 만들 때 선언하는 어노테이션이다. 

나는 제이쿼리에서 지원하는 ajax 통신을 이용했기 때문에 @RestController를 선언한 곳에서 작업 했어야 했으나.

 

@Controller가 선언된 곳에서 만들었고 @Controller 였기 때문에

view가 있어야 한다고 오류가 나왔던 것이였다.

 

자세한 내용은 아래를 참고 하길 바란다.

2022.07.17 - 내가 헷갈려서 정리한 @RestController @Controller @Response @RequestParam @RequestBody @ModelAttribute정리

 

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'📂 Troubleshooting & Ops' 카테고리의 다른 글

github action gradle.yml에러 input required and not supplied: OOO  (0) 2022.11.13
[Querydsl][오류] Cannot delete or update a parent row: a foreign key constraint fails  (0) 2022.07.08
[JAVA](모든 시도 해봄) / java.lang.ClassNotFoundException 오류 해결  (4) 2022.03.12
[파이어베이스]Error: EPERM: operation not permitted, unlink 'D:\Sources\**\node_modules\ 파이어베이스 연동 오류  (0) 2021.04.29
[Firebase] 배포 / deploy 실패, 빌드하는 방법 해결  (0) 2021.04.26
'📂 Troubleshooting & Ops' 카테고리의 다른 글
  • github action gradle.yml에러 input required and not supplied: OOO
  • [Querydsl][오류] Cannot delete or update a parent row: a foreign key constraint fails
  • [JAVA](모든 시도 해봄) / java.lang.ClassNotFoundException 오류 해결
  • [파이어베이스]Error: EPERM: operation not permitted, unlink 'D:\Sources\**\node_modules\ 파이어베이스 연동 오류
foodev
foodev
이것저것 개발과 이것저것 리뷰 합니다.
    반응형
    250x250
  • foodev
    개발 개맛집
    foodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (104) N
      • ⭐ Featured (4)
      • 📂 Backend Engineering (36)
      • 📂 Troubleshooting & Ops (10)
      • 📂 Infra & System (7) N
      • 📂 Reflections (21)
        • Year-in-Review (5)
        • Work & Career (10)
        • Lessons Learned (6)
      • 📂 Team Journal (10)
      • 📂 Archive (16)
  • 블로그 메뉴

    • 홈
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    창업패키지후기
    nestjs pipe
    azure ci/cd
    db 날린 썰
    인프라 로그 저장 비용 감소하는 방법
    스냅샷과히스토리성 차이
    typedi란
    Azure log 비용 줄이기
    해피해킹 카라비너
    db 초기화
    nestjs pipe body
    db 날림
    Azure 로그 최소 저장 30일
    validation failed (numeric string is expected)
    개발썰
    해피해킹 키매핑
    JPA
    스냅샷과 히스토리
    해피해킹 커스텀
    githubaction 라벨 배포
    QueryDSL
    di의존성
    di란
    토이프로젝트개발일지
    서이추
    해피해킹 방향키
    githubaction 라벨 ci/cd
    해피해킹 꿀팁
    typedi 동작원리
    di동작원리
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
foodev
[오류해결]template might not exist or might not be accessible by any of the configured Template Resolvers
상단으로

티스토리툴바