거누의 개발노트

No primary or single unique constructor found for interface org.springframework.data.domain.Pageable 본문

트러블 슈팅

No primary or single unique constructor found for interface org.springframework.data.domain.Pageable

Gogozzi 2022. 7. 8. 13:08
반응형

문제 발생 배경

@ApiOperation(value = "전체 게시글 목록 조회")
@ApiImplicitParams({
    @ApiImplicitParam(name = "filter", value = "카테고리(daily/challenge/my)", required = false, dataType = "string", paramType = "query"),
    @ApiImplicitParam(name = "keyword", value = "검색 키워드", required = false, dataType = "string", paramType = "query"),
    @ApiImplicitParam(name = "pageable", value = "페이징 값(size, page, sort)", required = false, dataType = "string", paramType = "query"),
    @ApiImplicitParam(name = "sub", value = "(제목/내용으로 검색)title/content", required = false, dataType = "string", paramType = "query")
})
@ApiImplicitParam(name = "Authorization", value = "Access Token", required = true, allowEmptyValue = false, paramType = "header", dataTypeClass = String.class, example = "access_token")
@GetMapping("/board")
public ResponseEntity<PageBoardResponseDto> getBoardList(
        @RequestParam(required = false) FilterEnum filter,
        @RequestParam(defaultValue = "") String keyword,
        @RequestParam(required = false) SubEnum sub,
        @PageableDefault(size=10, sort="createdDate", direction= Sort.Direction.DESC) Pageable pageable
) {
    LoadUser.loginAndNickCheck();
    PageBoardResponseDto responseDto = boardService.getBoardList(
            filter, keyword, pageable, LoadUser.getEmail(), sub
    );
    return ResponseEntity.status(HttpStatus.OK).body(responseDto);
}

전체 게시글 목록과 검색을 같이하는 API를 작성중에, 

No primary or single unique constructor found for interface org.springframework.data.domain.Pageable

해당 오류가 발생했다.

발생원인파악

https://stackoverflow.com/questions/52355490/no-primary-or-default-constructor-found-for-interface-org-springframework-data-d

 

No primary or default constructor found for interface org.springframework.data.domain.Pageable

I was trying to implement Pageable in my RestController and running into issues with this error message "No primary or default constructor found for interface org.springframework.data.domain.Pageab...

stackoverflow.com

Swagger config 클래스에 Pageable 을 파라미터로 받을 수 있게 설정해야한다는 내용이 있었다.

그래서 해당 페이지에서 나온데로 Swagger config에 아래 메소드를 추가해 주었다.

오류 해결

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    argumentResolvers.add( new PageableHandlerMethodArgumentResolver());
}
반응형
Comments