baomidou / dynamic-datasource

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

matchIfMissing should be false to improve the compatibility and flexibility of components and make integration easier #444

Closed wangzhiwei1314 closed 2 years ago

wangzhiwei1314 commented 2 years ago

What kind of change does this PR introduce? (check at least one)

The description of the PR:

Other information:

huayanYu commented 2 years ago

具体描述下场景,看起来是能合并的。 就是我还是不太理解场景。

wangzhiwei1314 commented 2 years ago

当我在module A中引入dynamic-datasource-spring-boot-starter依赖后(版本3.4.1),如果application.yml配置文件中未显式声明spring.datasource.dynamic.enabled: false,启动程序时会报错: Caused by: java.lang.RuntimeException: HikariConfig does not has 'copyState' or 'copyStateTo' method! at com.baomidou.dynamic.datasource.creator.HikariDataSourceCreator.fetchMethod(HikariDataSourceCreator.java:78) at com.baomidou.dynamic.datasource.creator.HikariDataSourceCreator.<clinit>(HikariDataSourceCreator.java:48) ... 133 common frames omitted 我希望能在不修改现有工程applicaiton.yml配置文件的情况下依赖module A(module A是底层模块,被多个模块依赖),但是由于DynamicDataSourceAutoConfiguration类中,@ConditionalOnProperty的matchIfMissing = true,所以会导致其他模块报错。

huayanYu commented 2 years ago

当我在module A中引入dynamic-datasource-spring-boot-starter依赖后(版本3.4.1),如果application.yml配置文件中未显式声明spring.datasource.dynamic.enabled: false,启动程序时会报错: Caused by: java.lang.RuntimeException: HikariConfig does not has 'copyState' or 'copyStateTo' method! at com.baomidou.dynamic.datasource.creator.HikariDataSourceCreator.fetchMethod(HikariDataSourceCreator.java:78) at com.baomidou.dynamic.datasource.creator.HikariDataSourceCreator.<clinit>(HikariDataSourceCreator.java:48) ... 133 common frames omitted 我希望能在不修改现有工程applicaiton.yml配置文件的情况下依赖module A(module A是底层模块,被多个模块依赖),但是由于DynamicDataSourceAutoConfiguration类中,@ConditionalOnProperty的matchIfMissing = true,所以会导致其他模块报错。

那是不是会影响到所有人,用这个项目必须主动声明spring.datasource.dynamic.enabled: true

wangzhiwei1314 commented 2 years ago

当我在module A中引入dynamic-datasource-spring-boot-starter依赖后(版本3.4.1),如果application.yml配置文件中未显式声明spring.datasource.dynamic.enabled: false,启动程序时会报错: Caused by: java.lang.RuntimeException: HikariConfig does not has 'copyState' or 'copyStateTo' method! at com.baomidou.dynamic.datasource.creator.HikariDataSourceCreator.fetchMethod(HikariDataSourceCreator.java:78) at com.baomidou.dynamic.datasource.creator.HikariDataSourceCreator.<clinit>(HikariDataSourceCreator.java:48) ... 133 common frames omitted 我希望能在不修改现有工程applicaiton.yml配置文件的情况下依赖module A(module A是底层模块,被多个模块依赖),但是由于DynamicDataSourceAutoConfiguration类中,@ConditionalOnProperty的matchIfMissing = true,所以会导致其他模块报错。

那是不是会影响到所有人,用这个项目必须主动声明spring.datasource.dynamic.enabled: true

嗯,确实会影响到其他人。如果大部分情况下都不配置spring.datasource.dynamic.enabled: true的话,把@ConditionalOnProperty中name = "enabled", havingValue = "true",matchIfMissing = true去掉是不是就两全其美了,哈哈。