You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/06/29 07:58:53 UTC
[GitHub] [incubator-shardingsphere] piantoutongyang opened a new issue
#2627: springboot2.0+mybatis-plus+sharding-jdbc3.x multi datasource cant work
piantoutongyang opened a new issue #2627: springboot2.0+mybatis-plus+sharding-jdbc3.x multi datasource cant work
URL: https://github.com/apache/incubator-shardingsphere/issues/2627
my project based on springboot2.0+mybatis-plus+sharding-jdbc3.x .
and i wanna have multi datasource (use @DB("xxxx")) but it just can't work.
here's my code:
application.yml
# 连接池通用配置
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
server:
port: 9999
sharding: #分库分表配置
jdbc:
datasource:
names: ds0,ds1
ds0:
type: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://127.0.0.1:3306/ds0?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
initialSize: ${initialSize}
minIdle: ${minIdle}
maxActive: ${maxActive}
maxWait: ${maxWait}
validationQuery: SELECT 1 FROM DUAL
timeBetweenEvictionRunsMillis: ${timeBetweenEvictionRunsMillis}
minEvictableIdleTimeMillis: ${minEvictableIdleTimeMillis}
ds1:
type: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://127.0.0.1:3306/ds1?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
initialSize: ${initialSize}
minIdle: ${minIdle}
maxActive: ${maxActive}
maxWait: ${maxWait}
validationQuery: SELECT 1 FROM DUAL
timeBetweenEvictionRunsMillis: ${timeBetweenEvictionRunsMillis}
minEvictableIdleTimeMillis: ${minEvictableIdleTimeMillis}
config:
masterslave: #读写分离
name: ms
load-balance-algorithm-type: round_robin
master-data-source-name: ds0
slave-data-source-names: ds1
props:
show: true
spring:
main:
allow-bean-definition-overriding: true
datasource:
dynamic:
primary: ds-svc0
datasource:
ds-svc0:
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/ds0
ds-svc1:
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/ds1
mybatis:
config-location:
classpath:
mybatis-config.xml
mapperLocations:
classpath:mapper/*.xml
java code:
@DS("ds-svc0")
public int addUser(User user) {
userMapper.insert(user);
System.out.println(("----- selectAll method test ------"));
List<User> userList = userMapper.selectList(null);
userList.forEach(System.out::println);
return 1;
}
@DS("ds-svc1")
public int addUser1(User user) {
userMapper.insert(user);
System.out.println(("----- selectAll method test ------"));
List<User> userList = userMapper.selectList(null);
userList.forEach(System.out::println);
return 1;
}
---
as you can see that i have two different datasources which are "ds-svc0" and "ds-svc1"
but when i run the code ,it showed the same datasource.
it drives me crazy.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services