Framework & Library/Spring Boot
-
Spring Boot - Custom ExceptionFramework & Library/Spring Boot 2022. 2. 14. 18:40
Custom Exception의 구조 Exception 클래스 ㆍ 위 사진은 Java에서 제공해주는 Exception 클래스에 대한 내용이다. ㆍ Exception 클래스는 Throwable 클래스를 상속받는 형태이다. ㆍ Exception 클래스의 생성자는 String 타입의 message를 받게 되는데, 해당 message가 클라이언트에게 전달될 메시지라는 것을 유추해볼 수 있다. Throwable 클래스 ㆍ 위 사진은 Exception 클래스가 상속받고 있는 Throwable 클래스에 대한 내용이다. ㆍ Exception 클래스의 생성자로부터 입력받은 message가 Throwable 클래스의 멤버 변수인 detailMessage로 된다는 것을 확인할 수 있다. ㆍ 또한, getMessage() 메..
-
Spring Boot - @ControllerAdvice, @ExceptionHandler를 활용한 전역 예외 처리Framework & Library/Spring Boot 2022. 2. 11. 18:28
예외 처리 예외 클래스 ㆍ 모든 Exception 클래스는 Throwable 클래스를 상속받고 있다. Checked Exception Uncheked Exception 처리여부 반드시 예외 처리 필요 명시적 처리 강제하지 않음 확인시점 컴파일 단계 실행 중 단뎨 예외 발생 시 트랜잭션 롤백 수행하지 않음 롤백 수행 대표 예외 1. IOException 2. SQLException 1. NullPointerException 2. IllegalArgumentException 3. IndexOutOfBoundException 4. SystemException ㆍ Exception 클래스는 수많은 자식 클래스가 있으며, 크게 Checked Exception과 Unchecked Exception으로 나눌 수 있다..
-
Spring Boot - 유효성 검사Framework & Library/Spring Boot 2022. 2. 10. 12:23
유효성 검사 유효성 검사란? ㆍ 서비스의 비즈니스 로직이 올바르게 동작하기 위해서는 사용되는 데이터에 대한 사전 검증하는 작업이 필요하다. 이러한 작업은 유효성 검사 또는 데이터 검증이라고 부르는데, 흔히 Validation이라고 한다. ㆍ 데이터의 검증은 Controller, Serivce와 같이 여러 계층에서 발생하는 흔한 작업이다. ㆍ Validation은 들어오는 데이터에 대해 의도한 형식의 값이 제대로 들어오는지 체크하는 과정을 뜻한다. 일반적인 유효성 검사의 문제점 ㆍ 일반적인 애플리케이션에서 사용되는 Validation 방식은 몇 가지 문제가 존재한다. ㆍ 단지, 다른 메서드에 위치해 있다는 이유만으로 유효성을 검사하는 코드들이 중복되게 작성되는 것이다. 따라서, 코드가 복잡해진다는 단점이 ..
-
Spring Boot - Logback 적용하기Framework & Library/Spring Boot 2022. 2. 9. 12:24
Logback Logback이란? - Logback이란 Log4j를 기반으로 개발된 로깅(Logging) 라이브러리이다. - Log4j에 비해 약 10배 정도 빠른 퍼포먼스를 자랑하며, 메모리 효율성이 높다 - 출시 순서 : Log4j → Logback → Log4j2 Logback 특징 - 로그에 특정 레벨을 설정할 수 있다. 따라서, 실 운영과 테스트 상황에서 각각 다른 출력 레벨을 설정하여 로그를 확인이 가능하다. - 개발자가 선호하는 출력 방식을 설정할 수 있다. - 설정 파일을 일정 시간마다 스캔하여 관리하기 때문에, 애플리케이션의 중단 없이 설정의 변경이 가능하다. - 별도의 프로그램 없이 자체적으로 로그 압축을 지원한다. - 로그 보관 기간을 설정할 수 있다. 로그 레벨 Trace → Deb..
-
Spring Boot - ORM이란?Framework & Library/Spring Boot 2022. 2. 3. 23:59
ORM(Object Relational Mapping) ORM이란? - 애플리케이션의 객체와 관계형 데이터베이스의 데이터를 자동으로 매핑해주는 것을 의미한다. 즉, Java의 데이터 클래스와 관계형 데이터베이스의 테이블을 매핑해주는 것이다. - 객체지향 프로그래밍은 클래스를 사용하고, 관계형 데이터베이스는 테이블을 사용하기 때문에 객체 모델과 관계형 모델 간에 불일치가 존재한다. 이러한 차이로부터 발생하는 제약사항을 해결해주는 역할을 수행하는 것이 바로 ORM 기술이다. - ORM 기술의 대표적인 예로 JPA, Hibernate 등이 있다. ORM의 장점 - SQL 쿼리가 아닌 직관적인 코드로 데이터를 조작할 수 있다. ㆍ 개발자가 보다 비즈니스 로직에 집중하여 개발할 수 있다. - 재사용 및 유지보수가..
-
Spring Boot - 서비스 구조 살펴보기Framework & Library/Spring Boot 2022. 2. 3. 13:53
Spring Boot 서비스 구조 Entity(Domain) - DB에 쓰일 칼럼과 여러 Entity 값의 연관관계를 정의한 것이다. - DB의 테이블을 하나의 Entity 클래스로 생각해도 무방하다. - 실제 DB의 테이블과 1:1로 매핑된다. - Entity 클래스의 필드는 각 테이블 내부의 칼럼을 의미한다. Repository - DB에 접근하는 메서드를 사용하기 위한 인터페이스이다. - Service와 DB를 연결하는 고리의 역할을 수행한다. - DB에 적용하고자 하는 CRUD를 정의하는 영역이다. DAO(Data Access Object) - DB에 접근하는 객체를 의미한다. - Service가 DB에 연결할 수 있게 도와주는 역할을 수행한다. - DB에 접근하여 데이터를 조회하거나 조작하는 기..