[Spring, Feign] 객체를 쿼리 스트링으로 전달하기

19·2024년 3월 8일
0

에러 모음

목록 보기
20/24

배경

Retrofit으로 다른 서비스에 요청을 보내다가, 이번에 Feign을 써보았다
요청할 때, 쿼리 스트링으로 데이터를 전달하는데 405 에러가 뱉어졌다

@FeignClient(~)
interface FeignExample {

	@GetMapping(/url)
    fun fetch(@ModelAttribute example: Example): Response
}
  • @ModelAttribute로 요청을 보냈다

심지어 Get메소드인데, Post메소드로 바뀌어버렸다
디버깅을 해보니, 객체를 JSON으로 바꿔버리면서 Http Method도 바뀌어버렸다


내가 한 방법

Feign에서는 @ModelAttribute로 할 수 없다 왜냐면 Spring MVC 어노테이션이니까

대신 @SpringQueryMap을 써서 할 수 있다

@FeignClient(~)
interface FeignExample {

	@GetMapping(/url)
    fun fetch(@SpringQueryMap example: Example): Response
}

참고

https://honeyinfo7.tistory.com/324

profile
하나씩 차근차근

0개의 댓글