This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
AbstractRoutingDataSource 클래스를 이용하여
TargetDataSources에 slave와 master DataSource를 등록하고
determineCurrentLookupKey 함수를 오버라이드하여
Slave Datasource와 Master DataSource중 선택하여 사용합니다.
어떤 데이터소스를 사용할지는 AOP를 사용하여 구현하였습니다.
메소드(Mapper) 시작전에 AOP를 이용하여 쓰레드로컬 변수에 마스터와 슬레이브중 한개를 넣어놓고
determineCurrentLookupKey함수에서 쓰레드로컬 변수를 가져와 어떤 데이터소스를 사용할지 정합니다.
determineCurrentLookupKey는 JDBC getConnection()함수에서 호출되어 데이터소스가 정해집니다.
자세한 설명은 다음 블로그에 정리하였습니다.
https://tjdrnr05571.tistory.com/14?category=876333
LazyConnectionDataSourceProxy를 사용한 이유
https://tjdrnr05571.tistory.com/15?category=876333