본문 바로가기
728x90

Spring Boot38

HttpMessageConverters : http요청 본문을 객체로 변환하거나, 객체를 http응답 본문으로 변경할 때 사용 @ResponseBody : 해당 객체의 converter를 사용해서 응답 return @RequestBody : 해당 객체의 converter를 사용해서 객체로 변환 @RestController public class UserController { @PostMapping("/userinfo") public @ResponseBody User postUserInformation(@RequestBody User user){ return user; } } * @ResponseBody은 @RestController를 사용하는 경우 생략 가능 Test 코드 @RunWith(SpringRunner.class) @WebMvcTes.. 2022. 2. 20.
Spring boot 단위 테스트 단위 테스트 (Slice Test) > 레이어별로 잘라서 테스트하고 싶은 경우 사용 방법 (이전의 예제 사용) 참고 : https://developing-countries.tistory.com/57 의 3번 예제 @WebMvcTest > web관련 Bean만 생성 > Service들을 MockBean으로 생성해줘야함 ex) @Controller, @ControllerAdvice, @JsonComponent @RunWith(SpringRunner.class) @WebMvcTest(SampleController.class) class SampleControllerTest { @Autowired MockMvc mockMvc; @MockBean SampleService mockSampleService; @Tes.. 2022. 2. 20.
Spring boot 통합 Test @SpringBootTest > @SpringBootApplication을 찾아가서 모든 BeanScan진행 @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) * junit4 기준 @RunWith와 같이 사용해야함 참고 : https://developing-countries.tistory.com/50?category=1023056 org.junit.runners.model.InvalidTestClassError org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.example.studyspringboot.S.. 2022. 2. 20.
Logging 로깅 퍼사드 > 프레임워크를 사용하는 애플리케이션들이 원하는 로거를 사용할 수 있도록 사용 ex) Commons Logging, SLF4j ... * Commons Logging / SLF4j 차이 - Commons Logging의 경우 runtime도중에 클래스 로거에서 로거를 찾음 - SLF4j 의존성 등을 통해 로거를 지정한 후 application 동작 > Spring 5에서 Spring-JCL 모듈을 통해 컴파일 시점에 SLF4j or Log4j2로 전환할 수 있도록 변경됨 > 사실상 SLF4j or Log4j2 둘 다 Logback을 사용해서 log를 찍음 참고 * --trace로 전부 디버깅모드로 log를 출력할 수 있음 * spring.output.ansi.enabled를 통해 컬러출력 가.. 2022. 2. 20.
728x90