-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: data source definition overriding #5798
fix: data source definition overriding #5798
Conversation
Signed-off-by: Dely <dph5199278@163.com>
|
没懂什么场景下需要这样操作,既然不想重复bean,不应该是把druid的starter依赖去掉么? |
有两个方面:
|
如: @Configuration
public class DataSourceConfig {
@Bean
@Primary
public DataSource dataSource() {
DynamicDataSource dynamicDataSource = new DynamicDataSource();
dynamicDataSource.setTargetDataSources(new HashMap<>());
return dynamicDataSource;
}
} 如上,我需要一个动态源来切换具体的使用源,而TargetDataSources使用的就是value为druid的数据源,这样就会触发上面的问题,并且这个在1.2.21版本上是不会有问题的,DynamicDataSource是我这边自定义的动态数据源,除了这个,starter的其他配置都是统一全局的 |
ci构建失败, 请本地运行 mvn clean install验证ok |
Signed-off-by: Dely <dph5199278@163.com>
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] druid-parent 1.2.23-SNAPSHOT ....................... SUCCESS [ 1.213 s]
[INFO] druid 1.2.23-SNAPSHOT .............................. SUCCESS [03:11 min]
[INFO] druid-spring-boot-starter 1.2.23-SNAPSHOT .......... SUCCESS [ 25.349 s]
[INFO] druid-wrapper 1.2.23-SNAPSHOT ...................... SUCCESS [ 0.214 s]
[INFO] druid-demo-petclinic 2.7.18 ........................ SUCCESS [ 22.051 s]
[INFO] druid-spring-boot-3-starter 1.2.23-SNAPSHOT ........ SUCCESS [ 20.881 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:21 min
[INFO] Finished at: 2024-03-27T19:43:46+08:00
[INFO] ------------------------------------------------------------------------ 已和本地一致,本地可以编译 |
Signed-off-by: Dely <dph5199278@163.com>
我这边发现从1.2.14升级到1.2.22发现一个问题,配置的最小连接数,初始化个数,最大连接数等都不生效,变成默认的了。升级到1.2.23又正常了。 配置类 |
修复由 #5671 导致无法设置其他默认数据源:
如下:
如果开启spring.main.allow-bean-definition-overriding=true,会导致dataSource被DruidDataSourceAutoConfigure覆盖出现问题。