문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
java:jdbc:replication [2014/12/25 21:54] kwon37xi 만듦 |
java:jdbc:replication [2023/02/16 13:51] (현재) kwon37xi [Java JDBC Replication Connection Pool (DataSource)] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
- | ====== Java JDBC Replication Connection Pool(DataSource) ====== | + | ====== Java JDBC Replication Connection Pool (DataSource) ====== |
Master/ | Master/ | ||
- | ===== Springframework ===== | + | * [[https:// |
+ | * [[java: | ||
+ | |||
+ | ===== Springframework | ||
Spring 프레임워크를 사용할 경우에는 [[http:// | Spring 프레임워크를 사용할 경우에는 [[http:// | ||
+ | |||
+ | 이 방식은 Spring Framework의 Transaction과 함께 사용할 때만 작동한다. | ||
+ | |||
+ | 최종적으로 '' | ||
+ | '' | ||
<code java> | <code java> | ||
줄 15: | 줄 23: | ||
} | } | ||
+ | // 실제로 Master DB에 접속하는 커넥션 풀 | ||
DataSource masterDataSource = ...; | DataSource masterDataSource = ...; | ||
+ | |||
+ | // 실제로 Slave DB에 접속하는 커넥션 풀 | ||
DataSource slaveDataSource = ...; | DataSource slaveDataSource = ...; | ||
// @Bean으로 생성 | // @Bean으로 생성 | ||
- | |||
ReplicationRoutingDataSource rrds = new ReplicationRoutingDataSource(); | ReplicationRoutingDataSource rrds = new ReplicationRoutingDataSource(); | ||
- | Map< | + | Map< |
targetDataSources.put(" | targetDataSources.put(" | ||
targetDataSources.put(" | targetDataSources.put(" | ||
줄 28: | 줄 38: | ||
rrds.setDefaultTargetDataSource(masterDataSource); | rrds.setDefaultTargetDataSource(masterDataSource); | ||
- | // 최종 사용은 LazyConnectionDataSourceProxy 로 해야한다. | + | // 최종적으로 Spring이 |
DataSource dataSource = new LazyConnectionDataSourceProxy(rrds); | DataSource dataSource = new LazyConnectionDataSourceProxy(rrds); | ||
</ | </ |