spring boot에서 아주 간단히 multi-datasource를 관리하고 jdbctemplate를 사용할 수 있는 예제를 소개한다.





먼저 maven또는 gradle 파일의 dependency에 db의 driver, spring-boot-starter-jdbc, commons-dbcp2를 추가한다.


build.gradle

compile("mysql:mysql-connector-java:5.1.36")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.apache.commons:commons-dbcp2:2.1.1")


application.yml

spring:
profiles : dev
activity_slave_db_0:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://db0.google.com:3306/test
username: develop
password : devteam
max-wait : 10000
max-active : 5
test-on-borrow: true
validationQuery: select 1
activity_slave_db_1:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://db1.google.com:3306/test
username: develop
password : devteam
max-wait : 10000
max-active : 5
test-on-borrow: true
validationQuery: select 1



Datasource 설정 

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class DatabaseConfig {

@Primary @Bean(name = "dsSlave0")
@ConfigurationProperties(prefix="spring.activity_slave_db_0")
public DataSource dsSlave0() {
return DataSourceBuilder.create().build();
}

@Bean(name = "dsSlave1")
@ConfigurationProperties(prefix="spring.activity_slave_db_1")
public DataSource dsSlave1() {
return DataSourceBuilder.create().build();
}

@Bean(name = "jdbcSlave0")
@Autowired
public JdbcTemplate slave0JdbcTemplate(@Qualifier("dsSlave0") DataSource dsSlave) {
return new JdbcTemplate(dsSlave);
}

@Bean(name = "jdbcSlave1")
@Autowired
public JdbcTemplate slave1JdbcTemplate(@Qualifier("dsSlave1") DataSource dsSlave) {
return new JdbcTemplate(dsSlave);
}

}




실제 DAO에서 사용하는 jdbctemplate 코드.

@Component
public class ActivitySlaveDao {
@Autowired
@Qualifier("jdbcSlave0")
private JdbcTemplate jdbcTemplate0;
@Autowired
@Qualifier("jdbcSlave1")
private JdbcTemplate jdbcTemplate1;
private List<JdbcTemplate> getJdbcTemplates() {
List list = Lists.newArrayList();
list.add(jdbcTemplate0);
list.add(jdbcTemplate1); }

// .. jdbcTemplate 사용. }


Posted by '김용환'
,


가장 큰 뉴스


* ms의 linked인 인수

http://www.huffingtonpost.kr/2016/06/14/story_n_10448016.html




1. Facebook의 추천 친구에 위치 정보를 활용하는지에 대한 의문 제기됨
ㄴ이로 인한 설정 변경 방법 소개
http://fusion.net/story/319108/facebook-phone-location-friend-suggestions/
http://www.cnet.com/how-to/how-to-turn-off-this-creepy-facebook-feature/
(한국 발 기사) http://news.joins.com/article/20230486
ㄴfacebook은 위치기반 추천 아니다고 얘기함
https://techcrunch.com/2016/06/28/facebook-says-its-not-making-friend-suggestions-based-on-your-location-after-all/


2. Facebook 표기 디자인 바뀜
http://www.theverge.com/2016/6/28/12046822/facebook-like-button-redesign
http://www.fnnews.com/news/201606291053198310



3. ios 10의 애플 메모리에 Facebook의 슬라이드 쇼우 기능 공개 - 스냅챗과 맞짱
http://www.cnet.com/news/facebooks-slideshow-feature-takes-on-apple-memories/
http://www.refinery29.com/2016/06/115290/facebook-slideshow-feature
모멘트 기능을 Facebook으로 집약함
(한국 발 기사) http://view.asiae.co.kr/news/view.htm?idxno=2016062808142874862


4. 페이스북의 전 직원의 책 - Chaos monkey 발간
http://money.cnn.com/2016/06/28/technology/facebook-culture-chaos-monkeys-antonio-garcia-martinez/
"Don't be deceived by my withering treatment of Facebook... Inside every cynic lives a heartbroken idealist."
Facebook declined to comment on the book.


5. 페이스북 메신저로 송금 기능에 대한 push 옵션 추가
https://techcrunch.com/2016/06/28/facebook-tests-new-option-that-pushes-users-to-send-money-on-messenger/
https://tctechcrunch2011.files.wordpress.com/2016/06/img_6267.png?w=764&h=680


6. 페이스북 프로필 (Intro)변경 
http://www.huffingtonpost.com/entry/facebook-intro-work_us_57694831e4b015db1bca97c9


7. 페이스북 라이브 방송으로 수익 (계약금만 600억)
한국발 뉴스 : http://www.businesspost.co.kr/news/articleView.html?idxno=29659


8. 인스타그램 월 이용자 5 억명 시대
http://www.huffingtonpost.kr/2016/06/22/story_n_10602580.html


9. 트위터 가상/증강현실 사업 속도 내기 위해 전 애플 UI 디자이너 영입
http://www.kbench.com/?q=node/164674


10. 트위터, 사진 꾸미고 검색 가능한 '스티커' 기능 출시
http://news.naver.com/main/read.nhn?mode=LSD&mid=sec&sid1=105&oid=001&aid=0008502142
http://imgnews.naver.net/image/001/2016/06/28/AKR20160628030500017_01_i_99_20160628082108.jpg?type=w540


11. 트위터, 동영상 업로드 140초 확대 등 비디오 기능 강화
http://www.rpm9.com/news/article.html?id=20160623090047
http://www.focus.kr/view.php?key=2016062200081854360
이와 함께 연예인, 정치인 등 영향력 있는 트위터 이용자가 팬들과 더욱 효율적으로 커뮤니케이션할 수 있도록 돕는 '트위터 인게이지'(Twitter Engage) 앱도 출시한다. 해당 앱을 통해 작성한 트윗에 대한 이용자들의 반응을 초 단위로 빠르고 정확히 확인할 수 있으며 더욱 활발한 반응을 이끌어 낼 수 있는 활용 방식을 추천받을 수 있다. 


12. 트위터 밖에서 트윗 공유 쉬워진다
http://www.zdnet.co.kr/news/news_view.asp?artice_id=20160623094037&type=det&re=
22일(현지시간) 트위터는 자사 플랫폼 내의 다양한 콘텐츠들을 웹 사이트나 모바일 앱으로 옮겨주는 '임베디드 타임라인(embedded timeline)'을 누구나 더 쉽게 활용할 수 있도록 그 기능을 개선했다고 밝혔다.

임베디드 타임라인(embedded timeline)은 특정 계정이 올린 트윗이나 마음에 들어하는 트윗들, 특정 이용자가 관심 있는 계정을 모은 리스트, 다양한 주제로 이용자들이 큐레이션해 만든 컬렉션 타임라인 등을 트위터 외부의 웹 사이트나 모바일 앱 등에 게시할 수 있도록 해주는 기능이다.


13. 트위터, 인공지능 스타트업 '매직포니' 사들여 동영상 강화
http://news.naver.com/main/read.nhn?mode=LSD&mid=sec&sid1=101&oid=018&aid=0003568730
매직포니는 기계 학습을 통해 동영상의 화질을 개선하는 기술을 보유한 회사로 올해 초 저해상도 비디오의 해상도를 업그레이드 하는 알고리즘을 공개했다.




14. 사진을 업로드하면 360도로 만들어 주는(화각) facebook 기능 추가.

https://ko-kr.facebook.com/help/851697264925946

http://www.insight.co.kr/newsRead.php?ArtNo=65013




15. Facebook의 추천 친구에 위치 정보를 활용하는지에 대한 의문 제기됨
ㄴ이로 인한 설정 변경 방법 소개
http://fusion.net/story/319108/facebook-phone-location-friend-suggestions/
http://www.cnet.com/how-to/how-to-turn-off-this-creepy-facebook-feature/
(한국 발 기사) http://news.joins.com/article/20230486
ㄴfacebook은 위치기반 추천 아니다고 얘기함
https://techcrunch.com/2016/06/28/facebook-says-its-not-making-friend-suggestions-based-on-your-location-after-all/



16. Facebook 표기 디자인 바뀜


http://www.theverge.com/2016/6/28/12046822/facebook-like-button-redesign
http://www.fnnews.com/news/201606291053198310




17. ios 10의 애플 메모리에 Facebook의 슬라이드 쇼우 기능 공개 - 스냅챗과 맞짱
http://www.cnet.com/news/facebooks-slideshow-feature-takes-on-apple-memories/
http://www.refinery29.com/2016/06/115290/facebook-slideshow-feature
모멘트 기능을 Facebook으로 집약함
(한국 발 기사) http://view.asiae.co.kr/news/view.htm?idxno=2016062808142874862

18. 페이스북의 전 직원의 책 - Chaos monkey 발간
http://money.cnn.com/2016/06/28/technology/facebook-culture-chaos-monkeys-antonio-garcia-martinez/
"Don't be deceived by my withering treatment of Facebook... Inside every cynic lives a heartbroken idealist."
Facebook declined to comment on the book.

19. 페이스북 메신저로 송금 기능에 대한 push 옵션 추가
https://techcrunch.com/2016/06/28/facebook-tests-new-option-that-pushes-users-to-send-money-on-messenger/
https://tctechcrunch2011.files.wordpress.com/2016/06/img_6267.png?w=764&h=680

20. 페이스북 프로필 (Intro)변경 
http://www.huffingtonpost.com/entry/facebook-intro-work_us_57694831e4b015db1bca97c9

21. 페이스북 라이브 방송으로 수익 (계약금만 600억)
한국발 뉴스 : http://www.businesspost.co.kr/news/articleView.html?idxno=29659

22. 인스타그램 월 이용자 5 억명 시대
http://www.huffingtonpost.kr/2016/06/22/story_n_10602580.html

23. 트위터 가상/증강현실 사업 속도 내기 위해 전 애플 UI 디자이너 영입
http://www.kbench.com/?q=node/164674

24. 트위터, 사진 꾸미고 검색 가능한 '스티커' 기능 출시
http://news.naver.com/main/read.nhn?mode=LSD&mid=sec&sid1=105&oid=001&aid=0008502142
http://imgnews.naver.net/image/001/2016/06/28/AKR20160628030500017_01_i_99_20160628082108.jpg?type=w540

25. 트위터, 동영상 업로드 140초 확대 등 비디오 기능 강화
http://www.rpm9.com/news/article.html?id=20160623090047
http://www.focus.kr/view.php?key=2016062200081854360
이와 함께 연예인, 정치인 등 영향력 있는 트위터 이용자가 팬들과 더욱 효율적으로 커뮤니케이션할 수 있도록 돕는 '트위터 인게이지'(Twitter Engage) 앱도 출시한다. 해당 앱을 통해 작성한 트윗에 대한 이용자들의 반응을 초 단위로 빠르고 정확히 확인할 수 있으며 더욱 활발한 반응을 이끌어 낼 수 있는 활용 방식을 추천받을 수 있다. 

26. 트위터 밖에서 트윗 공유 쉬워진다
http://www.zdnet.co.kr/news/news_view.asp?artice_id=20160623094037&type=det&re=
22일(현지시간) 트위터는 자사 플랫폼 내의 다양한 콘텐츠들을 웹 사이트나 모바일 앱으로 옮겨주는 '임베디드 타임라인(embedded timeline)'을 누구나 더 쉽게 활용할 수 있도록 그 기능을 개선했다고 밝혔다.

임베디드 타임라인(embedded timeline)은 특정 계정이 올린 트윗이나 마음에 들어하는 트윗들, 특정 이용자가 관심 있는 계정을 모은 리스트, 다양한 주제로 이용자들이 큐레이션해 만든 컬렉션 타임라인 등을 트위터 외부의 웹 사이트나 모바일 앱 등에 게시할 수 있도록 해주는 기능이다.

27. 트위터, 인공지능 스타트업 '매직포니' 사들여 동영상 강화
http://news.naver.com/main/read.nhn?mode=LSD&mid=sec&sid1=101&oid=018&aid=0003568730
매직포니는 기계 학습을 통해 동영상의 화질을 개선하는 기술을 보유한 회사로 올해 초 저해상도 비디오의 해상도를 업그레이드 하는 알고리즘을 공개했다.




Posted by '김용환'
,