初始化dataSource和ctxHolder
2021-08-07 13:40:04 4 举报
Db相关
作者其他创作
大纲/内容
AbstractDataSource
step1
regist-success
init DynamicDataSourceContextHolderprivate static String current;public static List<String> dataSourceIds;
@Configuration@Import({DynamicDataSourceRegister.class})
GenericBeanDefinitionsetBeanClass(DynamicDataSource.class)
dataSource-init
initcustomDataSources
ImportBeanDefinitionRegistrar
EnvironmentAware
AbstractRoutingDataSource@Override\tprotected Object determineCurrentLookupKey() {\t\treturn DynamicDataSourceContextHolder.getDataSourceType();\t}
BeanDefinitionRegistryregisterBeanDefinition(GenericBeanDefinition)
initDefaultDataSource
step2.1
*根据LookupKey从resolvedDataSources中获取动态DataSource
DataSource
@override:setEnvironment
初始化DynamicDataSourceContextHolder并注册dataSourceBean
@override:registerBeanDefinitions
application.yml: custom.datasource
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://{ip}:{port}/{dbname}?XXX=XXX username: {username} password: {password} db-type: com.alibaba.druid.pool.DruidDataSourcecustom: datasource: names: data2 data2: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://{ip}:{port}/{dbname}?XXX=XXX username: {username} password: {password} db-type: com.alibaba.druid.pool.DruidDataSource ##################################### validation-query: SELECT 1 time-between-eviction-runs-millis: XXXXX min-evictable-idle-time-millis: XXXXX maximum-pool-size: XXX data3: ...
application.yml: spring.datasource
step2
step2.2
0 条评论
回复 删除
下一页