1. Spring 에서 사용하는 Rest Client에 대해서 설명해 주세요.
- 종류 : RestTemplate, WebClient
- 버전별 차이
Spring 3.0에서는 RestTemplate, 5.0에서는 WebFlux의 WebClient, 6.0에서는 HTTP Interface로 발전함
- 사용법 참고
https://stir.tistory.com/347
Spring 6.0 HTTP Interface 사용법 및 REST API Client 방식의 변화
이 글은 Spring 6.0의 HTTP Interface 사용법 및 REST API Client 방식의 변화를 설명하고자 합니다. 해당 내용은 깃헙에 올려져 있습니다. Spring 6.0 등장 2022년 11월 Spring 6.0 버전이 나왔습니다. 주요 특징이
stir.tistory.com
- RestTemplate vs WebClient
https://tecoble.techcourse.co.kr/post/2021-07-25-resttemplate-webclient/
RestTemplate과 WebClient
이 글은 자바에서 HTTP 요청을 써봤거나 써보려고 하는 독자를 대상을 작성하였습니다. 스프링 어플리케이션에서 HTTP 요청할 때 사용하는 방법으로 RestTemplate과 WebClient가 있다. 스프링 5.0 이전까
tecoble.techcourse.co.kr
2. @SpringBootTest와 @WebMvcTest의 차이점을 설명해 주세요.
@SpringBootTest는 프로젝트의 전체 컨텍스트를 로드하여 빈을 주입하기 때문에 속도가 느리고, 통합 테스트를 할 때 많이 사용한다. 많은 스프링 빈을 등록하여 테스트에 필요한 의존성을 추가하기 때문에, 필요한 빈만을 등록하여 테스트를 진행하고자 한다면 슬라이스 테스트 어노테이션인 @WebMvcTest를 사용하는 것이 더 효율적이다.
@WebMvcTest는 MVC 부분 슬라이스 테스트로, 보통 컨트롤러 하나만 테스트하고 싶을 때 사용한다. @WebMvcTest()의 프로퍼티로 테스트를 원하는 컨트롤러 클래스를 넣어준다. @WebMvcTest는 @Controller같은 웹과 관련된 빈만 주입되며 @Service와 같은 일반적인 @Component는 생성되지 않는 특성 때문에 해당 컨트롤러를 생성하는 데 필요한 다른 빈을 정의하지 못해 발생한다. 따라서 이런 경우에는 @MockBean을 사용해서 필요한 의존성을 채워주어야 한다.
https://docs.spring.io/spring-framework/reference/integration/rest-clients.html
REST Clients :: Spring Framework
WebClient is a non-blocking, reactive client to perform HTTP requests. It was introduced in 5.0 and offers an alternative to the RestTemplate, with support for synchronous, asynchronous, and streaming scenarios. WebClient supports the following: Non-blocki
docs.spring.io
'CS study' 카테고리의 다른 글
Answer the Question (7) (0) | 2023.07.27 |
---|---|
Answer the Question (6) (0) | 2023.07.26 |
Answer the Question (4) (0) | 2023.07.24 |
Answer the Question (3) (0) | 2023.07.21 |
Answer the Question (2) (0) | 2023.07.20 |