baomidou / dynamic-datasource

dynamic datasource for springboot 多数据源 动态数据源 主从分离 读写分离 分布式事务
https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611
Apache License 2.0
4.67k stars 1.19k forks source link

druid filter conf does not effect #7

Closed pan3793 closed 5 years ago

pan3793 commented 6 years ago

Enviroment

JDK Version: Oracle JDK 1.8.0_162

SpringBoot Version: 2.0.5.RELEASE

Starter Version: 2.2.1 (lastest at 20180919)

Describe

configurations at spring.datasource.druid.filter.*** does not effect. Actually there do load and create filter beans, but those filter beans does not inject into druid datasource bean.

Analyze

both at alibaba original druid-starter & this dynamic stater, loading spring.datasource.druid.filter.*** conf first, but then,

  1. at alibaba original druid-starter, it use DruidDataSourceWrapper to init druid data source, @Autowird inject the filter beans into ds;
  2. at this dynamic stater, just invoke setter to set spring.datasource.druid.filter.dynamic.datasource.*.filters strings to ds props (DataSourceFactory line 134), implicit invoke FilterManager.loadFilter() (DruidAbstractDataSource line 1325), it just new** a filter object without load any configuration instead of loading bean from spring.
huayanYu commented 6 years ago

so it is, but I dont know how to resolve it.. item datasource may need different filter

pan3793 commented 6 years ago

when use multi ds on ali original starter, it share fitlter beans first, and use reflection to create anothter filters which just in there own conf. it may be a solution.

huayanYu commented 5 years ago

the latest 2.2.3 version support global DruidConfiguration. However,I can not use filterBean, I use DatasourceFactory to create Datasource. If you have any idea, pls PR