반응형 전체 글74 [Spring] 단위 테스트 TDD(Test-driven Development) 테스트 주도 개발에서 사용하지만, 코드의 유지보수 및 운영 환경에서의 에러를 미리 방지하기 위해서 단위 별로 검증하는 테스트 프레임워크 단위테스트 작성한 코드가 기대하는 대로 동작을 하는지 검증하는 절차 JUnit Java기반의 단위 테스트를 위한 프레임워크 Annotation기반으로 테스트를 지원하며, Assert를 통하여, (예상, 실제)를 통해 검증 Jacoco Java코드의 코드 커버리지를 체크하는 라이브러리 결과를 html, xml, csv로 확인이 가능하다. JAVA 2022. 8. 19. [Spring] Server to Server 통신 - Custom Header, Json활용 아래와 같은 Json파일을 만들고자한다. 이러한 형태를 사용하는 이유는 json형식을 만드는 코드를 매번 작성할 필요없이 body 내용만을 변경하여 사용할 수있다. { "header":{ "responseCode": null }, "resBody":{ "name": "steve", "age": 10 } } 클라이언트 Req.java public class Req { private Header header; private T resBody; public static class Header { private String responseCode; public String getResponseCode() { return responseCode; } public void setResponseCode(String .. Spring 2022. 8. 19. [Spring] Server to Server 통신 - POST 클라이언트 UserRequest.java public class UserRequest { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "UserResponse{" + "name='" + name + '\'' + ", age=" + age + '}'; } } RestTemplateServi.. Spring 2022. 8. 19. [Spring] Server to Server 통신 - GET Server to Server통신 내 서버가 클라이언트가 되어 다른 서버에 요청을 보내고 응답받아 전달한다. 클라이언트 ApiController.java import com.example.client.dto.UserResponse; import com.example.client.service.RestTemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.w.. Spring 2022. 8. 16. [JS] 조코딩 4주차 강의 node.js 설치 https://nodejs.org/ko/ Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. nodejs.org node 버젼 확인 방법 : 터미널에서 node -v 명령 npm 사용하기 https://www.npmjs.com/ npm Bring the best of open source to you, your team, and your company Relied upon by more than 11 million developers worldwide, npm is committed to making JavaScript development elegant, productive, and safe.. Web 2022. 8. 13. [Spring] Filter & Interceptor + 비동기 Filter란? Web Appliation에서 관리하는 영역으로써 Spring Boot Framework에서 Client로 부터 오는 요청 / 응답에 대해서 최초 / 최종 단계의 위치에 존재한다. 이를 통해 요청 / 응답의 정보를 변경하거나, Spring에 의해서 데이터가 변환되기 전의 순수한 Client의 요청 / 응답 값을 확인 할 수 있다. 유일하게 ServletRequest, ServletResponse의 객체를 변환 할 수 있다. 주로 Spring Framework에서는 request / response의 Logging 용도로 활용되거나, 인증과 관련된 Logic들을 해당 Filter에서 처리한다. 이를 선 / 후 처리 함으로써, Service business logic과 분리 시킨다. Inte.. Spring 2022. 8. 12. [Spring] Validation & Exception 처리 Validation이란? 프로그래밍에 있어서 가장 필요한 부분이다. exception이 발생하는 것을 방지 하기 위해서 미리 검증하는 과정을 말한다. 검증해야할 값이 많은 경우 코드가 길어진다. 구현에 따라서 달라질 수 있지만 Service Logic과 분리가 필요하다. 흩어져 있는 경우 어디에서 검증을 하는지 알기 어려우며 재사용의 한계가 있다. 검증 Logic이 변경되는 경우 테스트코드 등 참조하는 클래스에서 Logic이 변경되어야 하는 부분이 발생할 수 있다. 스프링에서는 이러한 부분을 어노테이션을 제공하여 일부 해결할 수 있다. Validation 관련 어노테이션 @Size : 문자 길이 측정(int Type 불가) @NotNull : null 불가 @NotEmpty : null, "" 불가 @n.. Spring 2022. 8. 12. [Spring] AOP AOP (Aspect Oriented Programming) 관점지향 프로그램 어떤 로직을 기준으로 핵심적인 관점, 부가적인 관점으로 나누어서 보고 그 관점을 기준으로 각각 모듈화하겠다는 것이다. AOP에서 각 관점을 기준으로 로직을 모듈화한다는 것은 코드들을 부분적으로 나누어서 모듈화하겠다는 의미다. 이때, 소스 코드상에서 다른 부분에 계속 반복해서 쓰는 코드들을 발견할 수 있는 데 이것을 흩어진 관심사 (Crosscutting Concerns)라 부른다. 흩어진 관심사를 Aspect로 모듈화하고 핵심적인 비즈니스 로직에서 분리하여 재사용하겠다는 것이 AOP의 취지다. 스프링 어플리케이션은 특별한 경우를 제외하고는 MVC 웹 어플리케이션에서는 Web Layer, Business Layer, Data L.. Spring 2022. 8. 10. [Spring] IoC (제어 역전) / DI (의존성 주입) Spring 삼각형 POJO를 중심으로 IoC / Di (의존 관계 주입), AOP (관점 중심 프로그램), PSA (이식 가능한 추상화) IoC (Inversion of Control) 스프링에서는 일반적인 Java 객체를 new로 생성하여 개발자가 관리하는 것이 아닌 Spring Container에 모두 맡긴다. 즉, 개발자에서 프레임워크로 제어의 객체 관리의 권한이 넘어갔음으로 '제어의 역전' 이라 한다. DI (Dependency Injection) 외부로부터 내가 사용하는 객체를 주입받는 방식. 스프링에서 빈을 주입받을 수 있는 장소 : 변수, 생성자, set메서드 DI 장점 의존성으로 부터 격리시켜 코드 테스트에 용이하다. DI를 통하여, 불가능한 상황을 Mock와 같은 기술을 통하여, 안정적.. Spring 2022. 8. 9. [Spring] Object Mapper Object Mapper란? Text JSON을 Object로, Object를 Text JSON으로 바꿔주는 기능을 한다. object를 text로 변환 할때는 get method를 활용한다. text를 object로 변환할때는 default 생성자를 필요로 한다. 작성한 클래스가 object mapper에서 활용된다면 get이 메소드이름에 사용되어서는 안된다. ResponseApplicationTests.java import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.springf.. Spring 2022. 8. 9. [Spring] Response(응답) 내려주기 ApiController.java import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api") public class ApiController { //TEXT @GetMapping("/text") public String text(@RequestParam String account) { return account; } //JSON // req - object mapper - object - method - object - object mappe.. Spring 2022. 8. 9. [Spring] DELETE API DELETE API 리소스 삭제 CRUD : D 멱등성 : O 안정성 : X Path Variable : O Query Parameter : O Data Body : X DeleteApiController.java import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api") public class DeleteApiController { @DeleteMapping("/delete/{userId}") public void delete(@PathVariable String userId, @RequestParam String account) { System.out.println(userId); System.out.. Spring 2022. 8. 8. 이전 1 2 3 4 5 ··· 7 다음 💲 추천 글 반응형