thymeleaf와 Spring Security를 통해서 권한별로 볼 수 있게하는 메뉴를 설정을 하던 중, 갑작스럽게 아래와 같은 에러가 발생하였다.

 

There was an unexpected error (type=Internal Server Error, status=500).
org.thymelaf.context.IWebContext.getExchange()Lorg/thymeleaf/web/IWebExchange;
java.lang.NoSuchMethodError: org.thymeleaf.context.IWebContext.getExchange()Lorg/thymeleaf/web/IWebExchange;

구글링 결과 나오는 답이 최신버전의 thymeleaf-spring-security5를 사용할 때, 발생하는 일이라고 떠서, dependcy의 버전을 낮췄다.

<변경 전>

implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.1.1.RELEASE'

<변경 후>

implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.0.4.RELEASE'

이후에는 NoSuchMethodError가 발생하지 않았다.

쇼핑몰 프로젝트를 하던 중, 다음과 같은 오류가 발생하였다.

Caused by: java.lang.IllegalStateException: For queries with named parameters you need to provide names for method parameters; Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters

JPQL을 사용할 때, 발생되는 것으로 추정되었고, 당시의 나는 아래와 같은 레파지토리를 작성해뒀다.

@Query("SELECT new com.shop.dto.CartDetailDto(ci.id, i.itemNm, i.price, ci.count, im.imgUrl) " +
        "FROM CartItem ci, ItemImg im " +
        "JOIN ci.item i " +
        "WHERE ci.cart.id = :cartId " +
        "AND im.item.id = ci.item.id " +
        "AND im.repImgYn = 'Y' " +
        "ORDER BY ci.regTime DESC" )
List<CartDetailDto> findCartDetailDtoList(Long cartId);

검색 결과로는 @Param을 설정해라는 방식과 옵션에서 -parameters를 추가해라는 방식이 있었는데, 후자의 방법은 개인적으로 환경이 바뀌면 또 같은 상황이 일어나기 때문에 옳지 않다고 판단하였다.
@Param을 쓰는 방식으로 아래와 같이 수정하였다.

@Query("SELECT new com.shop.dto.CartDetailDto(ci.id, i.itemNm, i.price, ci.count, im.imgUrl) " +
        "FROM CartItem ci, ItemImg im " +
        "JOIN ci.item i " +
        "WHERE ci.cart.id = :cartId " +
        "AND im.item.id = ci.item.id " +
        "AND im.repImgYn = 'Y' " +
        "ORDER BY ci.regTime DESC" )
List<CartDetailDto> findCartDetailDtoList(@Param("cartId")Long cartId);

이후, IllegalStateException이 발생하지 않게 되었다.

+ Recent posts