此章节具体介绍一下淘宝TDDL具体配置和使用

1. Spring配置文件配置:
================spring-mybatis.xml 中配置=============
<bean id="dataSource" class="com.taobao.tddl.group.jdbc.TGroupDataSource" init-method="init" destroy-method="destroyDataSource">
<!-
appName gome_market_search_index :应用名称 名字随意起 有意义即可
dbGroupKey gome_market_search_index_group_0 :db组 名字随意起有意义即可 主要作用: 可以配置多个数据源 作为一组
->
<property name="appName" value="gome_market_search_index" />
<property name="dbGroupKey" value="gome_market_search_index_group_0" />
</bean>

2.1 用一张图了解TDDL配置

2.2 TDDL需要结合diamond使用,以下是diamond需要的相关配置,必须配置到默认组下 DEFAULT_GROUP

   
2.3===========配置数据源(ip端口等)===========
##com.taobao.tddl.atom.global.数据源名称 (gome_market_search_index_db_0)
com.taobao.tddl.atom.global.gome_market_search_index_db_0

##数据库ip地址
ip=10.144.43.141
#数据库端口
port=3306
##数据库名称
dbName=gome_market_prod
##数据库类型
dbType=mysql
#数据库状态
dbStatus=RW 2.4===========配置数据源(连接池)==============
##com.taobao.tddl.atom.app.应用名称.数据源名
com.taobao.tddl.atom.app.gome_market_search_index.gome_market_search_index_db_0

#数据库用户
userName=root
#最小连接数
minPoolSize=50
#最大连接数
maxPoolSize=100
#连接的最大空闲时间
idleTimeout=10
#等待连接的最大时间
blockingTimeout=5000
#预处理缓存大小
preparedStatementCacheSize=50
#数据库连接属性
connectionProperties=autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 2.5===========配置数据库(com.taobao.tddl.atom.passwd.数据库名.mysql.用户名)==========
com.taobao.tddl.atom.passwd.gome_market_prod.mysql.root ##数据库密码 root
encPasswd=-64d29910cc13d220ea2e89c490b1e4bf
encKey=f97xK9qh3BSXv5iy 2.6============配置dbGroup=====================
com.taobao.tddl.jdbc.group_V2.4.1_gome_market_search_index_group_0 #w0r1 0个读库连接 1个读库连接
gome_market_search_index_db_0:w0r1

上记2.5章节encPasswd 需要加密操作,根据encKey加密

SecureIdentityLoginModule.java  将代码拷贝到工程运行

package service;

import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec; import org.apache.commons.lang.StringUtils; public class SecureIdentityLoginModule { private static byte[] ENC_KEY_BYTES = "This is a finger".getBytes(); private String userName; private String password; public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getDecodedPassword() throws Exception {
return new String(decode(password));
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((userName == null) ? 0 : userName.hashCode());
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SecureIdentityLoginModule other = (SecureIdentityLoginModule) obj;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
return true;
} public static String encode(String encKey, String secret) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] kbytes = SecureIdentityLoginModule.ENC_KEY_BYTES;
if (StringUtils.isNotBlank(encKey)) {
kbytes = encKey.getBytes();
}
SecretKeySpec key = new SecretKeySpec(kbytes, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
BigInteger n = new BigInteger(encoding);
return n.toString(16);
} public static String encode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
return SecureIdentityLoginModule.encode(null, secret);
} public static String decode(String encKey, String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
byte[] kbytes = SecureIdentityLoginModule.ENC_KEY_BYTES;
if (StringUtils.isNotBlank(encKey)) {
kbytes = encKey.getBytes();
}
SecretKeySpec key = new SecretKeySpec(kbytes, "AES");
BigInteger n = new BigInteger(secret, 16);
byte[] encoding = n.toByteArray();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decode = cipher.doFinal(encoding);
return new String(decode);
} public static char[] decode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
return SecureIdentityLoginModule.decode(null, secret).toCharArray();
} public static void main(String[] args) throws Exception {
System.out.println("Encoded password: " + new String(SecureIdentityLoginModule.encode("f97xK9qh3BSXv5iy","root")));
System.out.println("decoded password: " + new String(SecureIdentityLoginModule.decode("5a826c8121945c969bf9844437e00e28"
)));
}

}

如果没有配置encKey 需要在diamond配置 一个dms组 dataid:decryptPasswordUrl   需要配置密码验证策略  建议不使用

3.工程pom文件中引入依赖  注意:此依赖不作为公共依赖

<dependency>
<groupId>com.taobao.tddl</groupId>
<artifactId>tddl-matrix</artifactId>
<version>5.1.7.g1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>tddl-repo-demo</artifactId>
<groupId>com.taobao.tddl</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.taobao.tddl</groupId>
<artifactId>tddl-config-diamond</artifactId>
<version>5.1.7.g1-SNAPSHOT</version>
</dependency>

4.使用中遇到的问题解决  maven工程排除此版本的依赖即可

淘宝TDDL配置以及使用的更多相关文章

  1. [转帖]剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)

    剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER) 博客分类: 原博客地址: http://qq85609655.iteye.com/blog/2035176 distrib ...

  2. TDDL-剖析淘宝TDDL

    TDDL-剖析淘宝TDDL 学习了:https://blog.csdn.net/sumj7011/article/details/78286741 Taobao Distribute Data Lay ...

  3. 带你剖析淘宝TDDL——Matrix层的分库分表配置与实现

    前言 在开始讲解淘宝的TDDL(Taobao Distribute Data Layer)技术之前,请允许笔者先吐槽一番.首先要开喷的是淘宝的社区支持做的无比的烂,TaoCode开源社区上面,几乎从来 ...

  4. 笔者带你剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)

    注:本文部分内容引用本人博客http://gao-xianglong.iteye.com/blog/1973591   前言 在开始讲解淘宝的TDDL(Taobao Distribute Data L ...

  5. 淘宝TDDL深入浅出

    前言 在开始讲解淘宝的 TDDL(Taobao Distribute Data Layer) 技术之前,请允许笔者先吐槽一番.首先要开喷的是淘宝的社区支持做的无比的烂, TaoCode 开源社区上面, ...

  6. npm淘宝镜像配置

    npm config set registry https://registry.npm.taobao.org

  7. 淘宝分布式数据层TDDL

    剖析淘宝 TDDL ( TAOBAO DISTRIBUTE DATA LAYER ) 注:原文:http://gao-xianglong.iteye.com/blog/1973591   前言 在开始 ...

  8. TDDL:来自淘宝的分布式数据层

    淘宝根据自身业务需求研发了TDDL(Taobao Distributed Data Layer)框架,主要用于解决分库分表场景下的访问路由(持久层与数据访问层的配合)以及异构数据库之间的数据同步,它是 ...

  9. 淘宝分布式数据层:TDDL[转]

    淘宝根据自己的业务特点开发了TDDL(Taobao Distributed Data Layer 外号:头都大了 ©_Ob)框架,主要解决了分库分表对应用的透明化以及异构数据库之间的数据复制,它是一个 ...

随机推荐

  1. c++之旅:类型的强制转换

    类型强制转换 在编程的时候我们经常遇到类型的强制转换,C++为此提供了更安全的转换方式,在编程中我们更多的应该采用C++提供的类型转换方式 基本类型转换 基本类型转换用的最多,一般将高精度转换为低精度 ...

  2. 使用CXF+Spring发布WebService,启动报错

    使用CXF+Spring发布WebService,启动报错,日志如下: 五月 12, 2017 9:01:37 下午 org.apache.tomcat.util.digester.SetProper ...

  3. docker issue-Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

    Here is my docker version when i run docker version : Client: Version: 1.8.1 API version: 1.20 Go ve ...

  4. Python面试题之列表推导式

    题目要求: 生成如下列表 [[0,0,0,0,0,],[0,1,2,3,4,],[0,2,4,6,8,],[0,3,6,9,12,]] (考察列表生成式和基本逻辑推理) 方法1: list1 = [] ...

  5. CSS Link(链接)

    CSS Link(链接) 不同的链接可以有不同的样式. 一.链接样式 链接的样式,可以用任何CSS属性(如颜色,字体,背景等). 特别的链接,可以有不同的样式,这取决于他们是什么状态. 这四个链接状态 ...

  6. spark client + yarn计算

    前提:完成hadoop + kerberos安全环境搭建. 安装配置spark client: 1. wget https://d3kbcqa49mib13.cloudfront.net/spark- ...

  7. ImportError: No module named argparse

    如果有root权限,可以运行: easy_install argparse 如果没有root权限,As a simple solution copy argparse.py from https:// ...

  8. LeetCode——remove-duplicates-from-sorted-list

    Question Given a sorted linked list, delete all duplicates such that each element appear only once. ...

  9. 解题报告:hdu1159 common consequence LCS裸题

    2017-09-02 17:07:42 writer:pprp 通过这个题温习了一下刚学的LCS 代码如下: /* @theme:hdu1159 @writer:pprp @begin:17:01 @ ...

  10. tp5---树形菜单

    composer require bluem/tree