Back End/Spring Boot
-
[Spring] RESTful API 설계 가이드Back End/Spring Boot 2021. 12. 1. 14:16
서버 개발자는 Over-Fetching 과 Under-Fetching 을 신경쓰며 API 를 디자인 해야한다. REST API 디자인 시 필요한 정보들을 잘 정리한 블로그 포스팅들을 공유한다. # 예시 (QueryString & PathVariable) /users // Fetch a list of users /users?occupation=programmer // Fetch a list of programmer user /users/123 // Fetch a user who has id 123 /users [GET] // Fetch a list of users /users [POST] // Create new user /users/123 [PUT] // Update user /users/123 [DEL..
-
[Spring] JUnit API 테스트 코드 작성 (MockMvc)Back End/Spring Boot 2021. 11. 30. 21:14
* MockMvc 는 API 컨트롤러를 테스트하기 위한 도구이다. # 주의사항 MockMvc 를 주입하려면 @AutoConfigureMockMvc 어노테이션이 필요하다. # 회원가입과 로그인 API 를 테스트하기 위한 테스트 코드 @SpringBootTest @Slf4j @AutoConfigureMockMvc public class LoginApiTest { @Autowired private UserRepository userRepository; @Autowired private MockMvc mockMvc; @Autowired private ObjectMapper objectMapper; @Test @DisplayName("SignUp & Login Test") public void AccountTes..
-
[Spring] JUnit - unsatisfied dependency mockmvc 에러Back End/Spring Boot 2021. 11. 30. 19:05
# 에러 사항 MockMvc Bean 을 주입 받지 못함 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.bookmarkmanager.bookmarkmanager.main.login.LoginApiTest': Unsatisfied dependency expressed through field 'mockMvc'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.test.web.servlet..
-
[Spring] Swagger - REST 웹 서비스의 문서화Back End/Spring Boot 2021. 10. 16. 15:45
# Swagger 란? REST 웹 프로젝트를 문서화 해주며, 이를 통해 관리 및 다른팀원들이 편리하게 API를 호출해보고 테스트 할 수 있는 프레임워크이다. # Spring Fox Swagger 사용법 1. Maven Repository 에서 Spring Boot Starter 검색 후 build.gradle 에 dependencies 추가 https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter/3.0.0 2. 프로젝트 실행 후, 설정된 도메인주소/swagger-ui/ 로 접속. (local 환경이라면 http://localhost:포트번호/swagger-ui/) # Swagger Annotation Annotation 적용대상 및..
-
[Spring] Jacoco - 코드 커버리지 체크하기(TDD)Back End/Spring Boot 2021. 10. 15. 18:41
# 코드 커버리지(Code Coverage)란? 코드 커버리지는 소프트웨어의 테스트를 논할 때 얼마나 테스트가 충분한가를 나타내는 지표 소프트웨어 테스트를 진행했을 때 코드 자체가 얼마나 실행되었냐는 것 Jacoco를 통해 눈으로 쉽게 확인 할 수 있다....! # Jacoco 사용법 (IDLE - IntelliJ) 1. 프로젝트 폴더의 build.gradle 파일의 plugins 에 id 'jacoco' 추가 후, gradle 리셋. 2. 우측의 Gradle 을 클릭하면, 'jacocoTestReport' 와 'test' 항목을 위의 스크린샷 처럼 확인 할 수 있음 3. 'test' 를 더블클릭하면 test 가 실행되며, 프로젝트 폴더의 build -> reports 폴더가 생성됨 4. reports-..
-
Spring) Lombok annotation 간단 정리Back End/Spring Boot 2021. 9. 17. 20:22
Annotation 을 달아놓으면 컴파일시 De-lombok 과정을 거쳐 자동으로 annotation의 기능에 따라 코드를 생성함 # 주요 Lombok Annotation Annotation 사용위치 기능 @NoArgsConstructor 클래스 기본생성자 생성(필수) @AllArgsConstructor 클래스 모든 선언된 멤버변수를 매개변수로 하는 생성자 생성 @RequiredArgsConstructor 클래스 초기화 되지않은 final 필드나, @NonNull 이 붙은 필드에 대한 생성자를 생성 @Getter 클래스 Getter 생성 @Setter 클래스 Setter 생성 @ToString 클래스 오버라이딩된 toString 생성 (클래스명 + 필드명) @EqualsAndHashCode 클래스 Equ..
-
[Spring] Filter 와 Interceptor 의 차이Back End/Spring Boot 2021. 9. 17. 20:07
# Spring에서의 Request 데이터 흐름도 Interceptor 의 반환형은 boolean, True 이면 다음단계로 데이터를 전송 Summary. 필터는 WAS(웹컨테이너)에 의해 관리가 되는 영역이고 인터셉터는 DispatcherServlet(스프링의 프론트컨트롤러) 이후 영역이므로 스프링에 의해 관리되는 영역이다. 공통점은 컨트롤러 진입전 실행로직을 작성할 수 있다는 것. 차이점은 필터는 스프링이 관리하지 않으므로, Spring Context를 사용할 수 없다는 것. 이로 인해 극명히 대조될 때는 에러핸들링을 해야할 때이다. 인터셉터는 @ControllerAdvice 로 스프링의 도움을 받아 객체지향적으로 예외처리를 할 수 있지만, 필터는 직접 response에 접근하여 예외처리를 하거나, ..