๐ก๋ฌธ์
API Controller๋ฅผ ํ ์คํธ ํ๋๋ฐ ์ ์ฑ๊ณตํ๋ ํ ์คํธ๊ฐ ๊ณ์ ์คํจํ๋ค.
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: No primary or single unique constructor found for interface org.springframework.data.domain.Pageable
ํ ์คํธ ์ฝ๋
mockMvc.perform(get("/api/v2/users")
.param("page", String.valueOf(page)))
.andExpect(status().isOk())
.andExpect(content().string(JsonUtil.objectToString(pageOneUsers)))
.andDo(print());
์ฝ๋
/**
* ํ์ ๋ฆฌ์คํธ ์กฐํ
*
* @return ํ์ ๋ฆฌ์คํธ
*/
@GetMapping
public ResponseEntity<List<ListResponseDto>> getAll(@PageableDefault(
page = 1,
sort = "createdAt",
direction = Sort.Direction.DESC) Pageable pageable) {
return ResponseEntity.ok(userService.getAllUsers(pageable));
}
๋ญ๊ฐ ๋ฌธ์ ์ฌ.
๐ ํด๊ฒฐ
mockmvc๋ฅผ ์ฌ์ฉํ ์น ์์ฒญ์์๋ ํ ์คํธ์ ํ์ํ ์ต์ํ์ ํ๊ฒฝ์ ์์ฑํ๊ธฐ ์ํด
๋ณดํต standaloneMockMvcBuilder๋ฅผ ์ด์ฉํด ์ด๊ธฐ ์ค์ ์ ํ๋๋ฐ, ์ฌ๊ธฐ์
.setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
์ด๋ ๊ฒ ํ์ด์ง ์ ๋ณด๋ฅผ ์ถ์ถํ์ฌ Pageable ์ธ์คํด์ค๋ฅผ ์ปจํธ๋กค๋ฌ ๋ฉ์๋์ ์ฃผ์ ํด์ฃผ๋ ์ค์ ์ ์ถ๊ฐ๋ก ํด์ฃผ๋ฉด ํด๊ฒฐ๋๋ค.
๋ฐ์ํ
'๐ Spring Framework > Spring Project' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
OutBox Pattern ์ ํ์ฉํ ๋ฉ์ผ ์ ์ก ์๋น์ค ๊ฐ๋ฐ [At Least Once] (0) | 2023.04.20 |
---|---|
[๋ฆฌํฉํ ๋ง] ๋๋ฉ์ธ ๋ชจ๋ธ ์ค์ฌ Clean Architecture ๋ก์ ๋ฆฌํฉํ ๋ง (0) | 2022.12.12 |
[Refactor] ํจํค์ง ๊ตฌ์กฐ์ ์์กด์ฑ (2) | 2022.10.14 |
[Redisson] ํธ๋์ญ์ ๋ฌธ์ ๋ฐ์ ๋ฐ ํด๊ฒฐ (0) | 2022.10.01 |
[Redisson]์ ์ด์ฉํ ๋ถ์ฐ Lock ๊ตฌํ & ๋์์ฑ ๋ฌธ์ ํด๊ฒฐ (2) | 2022.09.27 |