개발
-
[Spring Boot] Field Injection 을 추천하지 않는 이유개발 2022. 11. 22. 13:57
Dependency Injection 방법 세가지와 왜 @Autowired 로 필드 인젝션이 추천되지 않는가? Dependency Injection 3가지 방법 Field Injection Setter Injection Constructor Injection 1. Field Inejction 변수 선언부에 @Autowired Annotation을 붙인다. @Component public class SampleController { @Autowired private SampleService sampleService; } 그런데 이 필드 주입은 추천 되는 방법이 아니다. 이 외에 이후에 소개 될 Constructor Injection 을 더 추천하는데, 왜 그럴까? 1.1 Field Injection 을 사..
-
[DB] DB 조인 방식 3가지개발 2022. 1. 23. 16:42
물리적 Join 의 종류 Driving Table 과 Driven Table Join 시 먼저 액세스 되는 테이블과 아닌 테이블 Driving Table: 먼저 액세스 됨 Driven Table: 나중에 액세스 됨 Driving Table 은 DB 옵티마이저가 결정한다. DB Join의 방식 (물리적) Nested Loop Join https://coding-factory.tistory.com/756 2개 이상의 테이블에서 Driving Table 을 기준으로 Driven Table 을 스캔하여 결과를 서칭하는 것. 인덱스에 의한 랜덤 액세스에 기반하고 있으므로, Driving Table 서치 결과가 많을 수록 성능이 나빠짐. Driven Table 에는 조인을 위한 인덱스가 있어야만 한다. 이 때 Dr..
-
[JPA] bulk data batch 작업 시 유의점개발 2022. 1. 6. 15:58
JPA 벌크 데이터 작업 시 유의점 JPA 의 벌크성 작업은 영속성 컨텍스트와 무관하다. 기존 엔티티 수정 메커니즘 JPA 는 엔티티를 영속성 컨텍스트에 보관한 후, DB에 반영한다. 이 때 최초상태를 복사해서 저장해두고, 플러시 시점에서 스냅샷과 엔티티를 비교하여 변경사항만을 DB 에 반영한다. 기존 엔티티 수정 메커니즘은 다음과 같다. 트랜잭션을 커밋하기 전, 엔티티 매니저 내부에서 flush() 를 먼저 호출한다. 엔티티와 스냅샷을 비교해서 변경 지점을 찾는다. 변경사항이 있는 경우 쓰기지연 SQL 저장소에 SQL 문을 생성해서 저장해 둔다. DB에 비로소 commit 될 때, SQL Query 를 DB로 보내서 실제로 반영한다. 벌크 수정 메커니즘 그러나 벌크 작업은 앞서 설명했던 것처럼 영속성 ..
-
[CI] Jenkins 와 Github Webhook 으로 PR 유효성 체크하기개발 2021. 12. 29. 18:06
"CI"는 개발자를 위한 자동화 프로세스인 지속적인 통합(Continuous Integration)을 의미합니다. CI를 성공적으로 구현할 경우 애플리케이션에 대한 새로운 코드 변경 사항이 정기적으로 빌드 및 테스트되어 공유 리포지토리에 통합되므로 여러 명의 개발자가 동시에 애플리케이션 개발과 관련된 코드 작업을 할 경우 서로 충돌할 수 있는 문제를 해결할 수 있습니다. 보통 코드를 개발한 뒤 원격 서버에 배포를 하기 위해서는 다음과 같은 과정을 거친다. 각 단계에서 개발 툴들이 어떤 역할을 하는지는 여기를 체크하자. 이 포스팅에서는 오로지 CI 에 대해서만 다룬다. 코드를 지속적으로 통합하기 위해서는 개발자가 각자 로컬에서 작업한 코드 변화에 대해서 시스템 안정성이 보장되느냐가 매우 중요하다. 특히 어..
-
[JPA] Primary Key가 아닌 필드를 참조하는 Foreign Key 를 만들때개발 2021. 12. 12. 17:27
Primary Key가 아닌 필드를 참조하는 Foreign Key 를 만들때 @JoinColumn(referencedColumnName = [참조하는 필드 이름]) 오류 상황 Stock 이라는 테이블과 DailyStock 이라는 데이터 필드의 일대다(1:N) 매칭 시 일어난 문제이다. Price 는 Stock 의 tickerSymbol 이라는 필드를 참조하고 있다. Price @Entity public class Price { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "price_id") private Long priceId; @ManyToOne @JoinColumn(name = "ticker_symbol") priva..
-
[TDD] TDD 로 알고리즘 문제 풀어보기 - 프로그래머스 42626, 더 맵게개발 2021. 10. 31. 17:57
TDD 로 알고리즘 문제 풀어보기 - 프로그래머스 42626 단기적인 목표로는 Spring Reactive 앱을 TDD 로 구현하는 것이 목표이다. 그런데 TDD 개발 자체가 손에 익지 않아서 처음부터 적용하기에는 무리가 있다. 알고리즘 코딩테스트 문제들은 input 과 output 의 명세가 명확하다. 따라서 tdd 연습에 매우 적합하다고 생각했다. 프로그래머스 42626 번 문제 문제 분석 문제의 핵심은 가장 작은 숫자와 두번째로 작은 숫자를 계속 섞다가, 더이상 섞을 수 없는 지점을 정의하는 것이다. 따라서 먼저 함수의 테스트가 필요한 경우의 수를 잘게 쪼개서 리스트업 해보았다. 테스트 조건 가장 작은 원소를 똑바로 고르는가 두번째로 작은 원소를 똑바로 고르는가 1, 2의 결과를 섞을 때 올바른 연..
-
[Spring Boot] Logging 과 @slf4j 에 대해서개발 2021. 10. 29. 23:50
logging-slf4j.md 가장 간단한 방법 System.out.println() 을 이용하기 로그의 양이나 로그 레벨을 조절 할 수 없다. 출력된 로그를 파일 등에 저장하기 불편하다 느리다. 1) java.util.logging JDK 1.4 부터 포함된 표준 로깅 API 2) Apache Commons logging 3) Log4j 4 SLF4J - logging Facade(퍼사드) SLF4J 는 로깅 퍼사드임. 로깅에 대한 추상 레이어를 제공하는 interface 왜 쓰는가? 어플리케이션은 SLF4J 를 사용해서 어떤 로깅 라이브러리를 쓰더라도 같은 방식으로 로그를 남겨야함 로그 라이브러리를 교체하더라도 코드 변경 불필요 4) Logback 로깅 퍼사드의 구현체 중 하나임 이점 오랫동안 검증 ..
-
[Web] Web Server 와 WAS개발 2021. 10. 28. 19:07
WAS 와 Web Server 웹서버 웹서버는 클라이언트로부터 요청을 받아서 정적인 컨텐츠를 내려준다. 혹은 HTTP 프로토콜을 기반으로 하여 클라이언트(웹 브라우저 또는 웹 크롤러)의 요청을 서비스 하는 기능을 담당한다. 기능 1) 정적인 컨텐츠 제공 WAS를 거치지 않고 바로 자원을 제공한다. 기능 2) 동적인 컨텐츠 제공을 위한 요청 전달 HTTP 형태로 Request 와 Response 를 주고 받을 수 있다. 클라이언트의 요청(Request)을 WAS에 보내고, WAS가 처리한 결과를 클라이언트에게 전달(응답, Response)한다. WAS DB 조회나 다양한 로직 처리를 요구하는 동적인 컨텐츠를 제공하기 위해 만들어진 Application Server 웹 컨테이너, 서블릿 컨테이너 라고도 말한..
-
Http 파라미터 방식과 멱등성개발 2021. 10. 28. 19:05
Http 파라미터 받는 방식 정리 오늘 좀 어이없는 이슈가 있었는데 정리해보려고 한다. 1. 오늘 있었던 일 프론트에서 특정 post method api 가 500 에러가 뜬다는 이슈 발생 swagger 에서 테스트해보니 너무 잘 동작함 즉 에러 재현이 안됨 프론트쪽에 request url 어떻게 보냈는지 여쭤 봄 프론트에서는 post method 이니 당연히 body data 로 파라미터를 보냄 그런데 그 api 는 query param 을 받는 post method api 였음 위 과정 약 1시간 반 소요.. 2. 문제 분석 path param, query param, body data 의 차이를 몰랐다 POST 에서는 늘 body data 로 파라미터를 받아 왔는데, 이 API 만 Query Par..
-
@Transactional 태그 안에서 Exception Handling 시 유의 할 점개발 2021. 8. 27. 00:04
@Transactional 태그 안에서 Exception Handling 시 유의 할 점 컨텍스트 설명 1. 요구사항 로그인이 실패할 때마다 그 횟수를 세고, 틀린 횟수가 5가 될 경우 계정을 잠금처리 해주세요 2. 내 접근법 로그인 시 비밀번호가 틀렸을 경우 member table 의 특정 필드를 +1 해주고, 그 필드 값이 5와 같을 경우 Exception 을 던지자 3. 마주친 문제 기존 코드는 이랬다. @Service public class AuthService { @Transactional(propagation = Propagation.REQUIRES_NEW) public UserProj authenticate(String emailAddress, String password) { UserPro..