yml配置:
#服务端口
server:
port: 8081
#服务名
spring:
application:
name: sharding-jdbc-examples
http:
encoding:
enabled: true
charset: utf-8
force: true
main:
allow-bean-definition-overriding: true
#shardingsphere相关配置
shardingsphere:
datasource:
names: m1 #配置库的名字,随意
m1: #配置目前m1库的数据源信息
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/course_db?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root
password: root
sharding:
tables:
a31: # 指定t_order表的数据分布情况,配置数据节点
#actualDataNodes: m1.a31_$->{1..2}
actualDataNodes: m1.a31_${1..2}
tableStrategy:
inline: # 指定t_order表的分片策略,分片策略包括分片键和分片算法
shardingColumn: id
#algorithmExpression: a31_$->{id % 2 + 1}
algorithmExpression: a31_${id % 2 + 1}
keyGenerator: # 指定t_order表的主键生成策略为SNOWFLAKE
type: SNOWFLAKE #主键生成策略为SNOWFLAKE
column: id #指定主键
props:
sql:
show: true
#日志打印
logging:
level:
root: info
org.springframework.web: info
com.serviceb.dao: debug
druid.sql: debug