1. Spring 에서 사용하는 Rest Client에 대해서 설명해 주세요.
더보기
Rest API 서버에 HTTP 요청을 보낼 수 있는 클라이언트 툴 또는 라이브러리임 즉, Http 통신을 할 수 있는 Rest한 Client라고 생각하면 된다.
- 종류 : RestTemplate, WebClient
- 버전별 차이
Spring 3.0에서는 RestTemplate, 5.0에서는 WebFlux의 WebClient, 6.0에서는 HTTP Interface로 발전함
- 사용법 참고
https://stir.tistory.com/347
- RestTemplate vs WebClient
https://tecoble.techcourse.co.kr/post/2021-07-25-resttemplate-webclient/
- 종류 : RestTemplate, WebClient
- 버전별 차이
Spring 3.0에서는 RestTemplate, 5.0에서는 WebFlux의 WebClient, 6.0에서는 HTTP Interface로 발전함
- 사용법 참고
https://stir.tistory.com/347
- RestTemplate vs WebClient
https://tecoble.techcourse.co.kr/post/2021-07-25-resttemplate-webclient/
2. @SpringBootTest와 @WebMvcTest의 차이점을 설명해 주세요.
더보기
@SpringBootTest는 프로젝트의 전체 컨텍스트를 로드하여 빈을 주입하기 때문에 속도가 느리고, 통합 테스트를 할 때 많이 사용한다. 많은 스프링 빈을 등록하여 테스트에 필요한 의존성을 추가하기 때문에, 필요한 빈만을 등록하여 테스트를 진행하고자 한다면 슬라이스 테스트 어노테이션인 @WebMvcTest를 사용하는 것이 더 효율적이다.
@WebMvcTest는 MVC 부분 슬라이스 테스트로, 보통 컨트롤러 하나만 테스트하고 싶을 때 사용한다. @WebMvcTest()의 프로퍼티로 테스트를 원하는 컨트롤러 클래스를 넣어준다. @WebMvcTest는 @Controller같은 웹과 관련된 빈만 주입되며 @Service와 같은 일반적인 @Component는 생성되지 않는 특성 때문에 해당 컨트롤러를 생성하는 데 필요한 다른 빈을 정의하지 못해 발생한다. 따라서 이런 경우에는 @MockBean을 사용해서 필요한 의존성을 채워주어야 한다.
https://docs.spring.io/spring-framework/reference/integration/rest-clients.html
'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 |