使用环境:
springboot 2.7.5
shardingsphere-jdbc-core 5.3.0
snakeyaml 1.33
场景、问题:
application.yml
server:
port: 20010
spring:
application:
name: announce_service
datasource:
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
url: jdbc:shardingsphere:classpath:sharding.yaml
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
sharding.yaml
dataSources:
ds_1:
dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: xxxxx
username: xxxxx
password: xxxxx
initial-size: 5
max-active: 20
min-idle: 5
max-wait: 60000
test-while-idle: true
validation-query: SELECT 1
db-type: mysql
test-on-borrow: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 30000
max-pool-prepared-statement-per-connection-size: 20
pool-prepared-statements: true
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
use-global-data-source-stat: true
keep-alive: true
filter:
wall:
db-type: mysql
enable:
true
ds_2:
dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: xxxxx
username: xxxxx
password: xxxxx
initial-size: 5
max-active: 20
min-idle: 5
max-wait: 60000
test-while-idle: true
validation-query: SELECT 1
db-type: mysql
test-on-borrow: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 30000
max-pool-prepared-statement-per-connection-size: 20
pool-prepared-statements: true
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
use-global-data-source-stat: true
keep-alive: true
filter:
wall:
db-type: mysql
enable:
true
ds_3:
dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: xxxxx
username: xxxxx
password: xxxxx
initial-size: 5
max-active: 20
min-idle: 5
max-wait: 60000
test-while-idle: true
validation-query: SELECT 1
db-type: mysql
test-on-borrow: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 30000
max-pool-prepared-statement-per-connection-size: 20
pool-prepared-statements: true
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
use-global-data-source-stat: true
keep-alive: true
filter:
wall:
db-type: mysql
enable:
true
rules:
- !READWRITE_SPLITTING
dataSources:
readwrite_ds:
staticStrategy:
writeDataSourceName: ds_1
readDataSourceNames:
- ds_2
- ds_3
loadBalancerName: random
loadBalancers:
random:
type: RANDOM
props:
sql-show: true
已进行操作:
@SpringBootTest
public class DataSourceTest {
@Autowired
private DataSource dataSource;
@Test
void dataSourceTest(){
System.out.println(dataSource.getClass());
DruidDataSource druid = (DruidDataSource) dataSource;
System.out.println(druid.getUsername());
}
}
打印
class com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper
null
现状:
Druid配置没有生效请问我该如何更改?