package com.example.dume.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
import java.sql.SQLException;
/**
* @author dume
* @create 2021-12-15 14:41
**/
@Configuration
public class DataSource1Value {
@Value("${spring.datasource1.url}")
private String url;
@Value("${spring.datasource1.username}")
private String username;
@Value("${spring.datasource1.password}")
private String password;
@Value("${spring.datasource1.driver-class-name}")
private String driverClassName;
@Value("${spring.datasource1.initialSize}")
private int initialSize;
@Value("${spring.datasource1.minIdle}")
private int minIdle;
@Value("${spring.datasource1.maxActive}")
private int maxActive;
@Value("${spring.datasource1.maxWait}")
private int maxWait;
@Value("${spring.datasource1.timeBetweenEvictionRunsMillis}")
private int timeBetweenEvictionRunsMillis;
@Value("${spring.datasource1.minEvictableIdleTimeMillis}")
private int minEvictableIdleTimeMillis;
@Value("${spring.datasource1.validationQuery}")
private String validationQuery;
@Value("${spring.datasource1.testWhileIdle}")
private boolean testWhileIdle;
@Value("${spring.datasource1.testOnBorrow}")
private boolean testOnBorrow;
@Value("${spring.datasource1.testOnReturn}")
private boolean testOnReturn;
@Value("${spring.datasource1.poolPreparedStatements}")
private boolean poolPreparedStatements;
@Value("${spring.datasource1.maxPoolPreparedStatementPerConnectionSize}")
private int maxPoolPreparedStatementPerConnectionSize;
@Value("${spring.datasource1.filters}")
private String filters;
@Value("${spring.datasource1.connectionProperties}")
private String connectionProperties;
@Value("${spring.datasource1.useGlobalDataSourceStat}")
private boolean useGlobalDataSourceStat;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public int getInitialSize() {
return initialSize;
}
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
public int getMinIdle() {
return minIdle;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
public int getMaxActive() {
return maxActive;
}
public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}
public int getMaxWait() {
return maxWait;
}
public void setMaxWait(int maxWait) {
this.maxWait = maxWait;
}
public int getTimeBetweenEvictionRunsMillis() {
return timeBetweenEvictionRunsMillis;
}
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
public int getMinEvictableIdleTimeMillis() {
return minEvictableIdleTimeMillis;
}
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public String getValidationQuery() {
return validationQuery;
}
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
public boolean isTestWhileIdle() {
return testWhileIdle;
}
public void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
public boolean isTestOnBorrow() {
return testOnBorrow;
}
public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}
public boolean isTestOnReturn() {
return testOnReturn;
}
public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}
public boolean isPoolPreparedStatements() {
return poolPreparedStatements;
}
public void setPoolPreparedStatements(boolean poolPreparedStatements) {
this.poolPreparedStatements = poolPreparedStatements;
}
public int getMaxPoolPreparedStatementPerConnectionSize() {
return maxPoolPreparedStatementPerConnectionSize;
}
public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) {
this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
}
public String getFilters() {
return filters;
}
public void setFilters(String filters) {
this.filters = filters;
}
public String getConnectionProperties() {
return connectionProperties;
}
public void setConnectionProperties(String connectionProperties) {
this.connectionProperties = connectionProperties;
}
public boolean isUseGlobalDataSourceStat() {
return useGlobalDataSourceStat;
}
public void setUseGlobalDataSourceStat(boolean useGlobalDataSourceStat) {
this.useGlobalDataSourceStat = useGlobalDataSourceStat;
}
@Primary
@Bean(name = "db1")
public DataSource masterDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
System.err.println("druid configuration initialization filter: " + e);
}
datasource.setConnectionProperties(connectionProperties);
return datasource;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
springboot多数据源,DruidDataSource多数据源切换,不重启项目,修改数据库名解决方案
共121个文件
xml:82个
java:17个
sql:3个
5星 · 超过95%的资源 需积分: 5 16 下载量 140 浏览量
2022-01-04
13:36:47
上传
评论 2
收藏 129KB ZIP 举报
温馨提示
项目背景: 1. Springboot项目 2. 一个主数据源,数据名称库不变。 3. 一个副数据源,数据库名称每天都在变,比如今天1号,是db_01; 明天2号,是db_02。 4.不重启项目切换数据源。 5.项目介绍: https://blog.csdn.net/qq_38105536/article/details/122296977
资源详情
资源评论
资源推荐
收起资源包目录
springboot多数据源,DruidDataSource多数据源切换,不重启项目,修改数据库名解决方案 (121个子文件)
$PRODUCT_WORKSPACE_FILE$ 489B
17c150137fb9f1540380b6316337bcb3cbe25291 0B
4918b103466093499cb68ef0209d61d503eac2a2 0B
4a32cda2318c55427ff322b3adb73b1c921e5871 124B
511e2dd62f19c7f68574afae4821f42f0df6fab7 0B
58ce01c447862da66578a7d5eebc86c053ecf1e4 731B
7a8e2119b65a2ee39f93fa6d07943ecfbe5b7be9 0B
9a70fa497e7122fb5dd8da03dd08d2957d4ee1da 202B
c189ec297bfbf24c104cfc0d554aea8098599a7f 179B
mvnw.cmd 6KB
d8588db536cb241557e1c51612f980b12f51cb19 0B
.gitignore 395B
dume.iml 9KB
maven-wrapper.jar 50KB
DataSource1Value.java 7KB
DataSource2Value.java 7KB
MavenWrapperDownloader.java 5KB
ChangeTableController.java 3KB
DataSource1Config.java 3KB
DataSource2Config.java 2KB
ChangeTable.java 1KB
MainTable.java 1KB
SpringUtil.java 1KB
MainTableController.java 814B
ChangeTableServiceImpl.java 803B
MainTableServiceImpl.java 785B
SpringbootApplicationMain.java 675B
ChangeTableDao.java 361B
MianTableDao.java 356B
ChangeTableService.java 315B
MainTableService.java 308B
HELP.md 891B
mvnw 10KB
index.pb 1KB
maven-wrapper.properties 218B
change_db_202112.sql 1KB
change_table.sql 1KB
change_db_202111.sql 1KB
uiDesigner.xml 9KB
workspace.xml 5KB
pom.xml 3KB
Project_Default.xml 1KB
compiler.xml 803B
Maven__org_springframework_boot_spring_boot_test_autoconfigure_2_1_2_RELEASE.xml 769B
Maven__org_springframework_boot_spring_boot_starter_logging_2_1_2_RELEASE.xml 748B
Maven__org_springframework_boot_spring_boot_starter_tomcat_2_1_2_RELEASE.xml 741B
Maven__org_springframework_boot_spring_boot_autoconfigure_2_1_2_RELEASE.xml 734B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_3_2.xml 730B
Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_8.xml 729B
Maven__org_springframework_boot_spring_boot_starter_jdbc_2_1_2_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_test_2_1_2_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_json_2_1_2_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_aop_2_1_2_RELEASE.xml 720B
Maven__org_springframework_boot_spring_boot_starter_web_2_1_2_RELEASE.xml 720B
MainTableMapper.xml 715B
Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml 700B
ChangeTableMapper.xml 697B
Maven__org_springframework_boot_spring_boot_starter_2_1_2_RELEASE.xml 692B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_3_2.xml 688B
Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_8.xml 688B
Maven__org_hibernate_validator_hibernate_validator_6_0_14_Final.xml 681B
Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_8.xml 674B
Maven__org_springframework_boot_spring_boot_test_2_1_2_RELEASE.xml 671B
Maven__org_apache_tomcat_embed_tomcat_embed_websocket_9_0_14.xml 660B
Maven__org_springframework_spring_expression_5_1_4_RELEASE.xml 658B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml 644B
Maven__org_springframework_spring_context_5_1_4_RELEASE.xml 637B
Maven__org_springframework_boot_spring_boot_2_1_2_RELEASE.xml 636B
Maven__com_alibaba_druid_spring_boot_starter_1_1_22.xml 633B
Maven__org_springframework_spring_webmvc_5_1_4_RELEASE.xml 630B
Maven__org_apache_tomcat_embed_tomcat_embed_core_9_0_14.xml 625B
Maven__org_springframework_spring_beans_5_1_4_RELEASE.xml 623B
Maven__com_fasterxml_jackson_core_jackson_databind_2_9_8.xml 623B
Maven__org_springframework_spring_test_5_1_4_RELEASE.xml 616B
Maven__org_springframework_spring_jdbc_5_1_4_RELEASE.xml 616B
Maven__org_springframework_spring_core_5_1_4_RELEASE.xml 616B
Maven__javax_activation_javax_activation_api_1_2_0.xml 611B
Maven__javax_validation_validation_api_2_0_1_Final.xml 611B
Maven__javax_annotation_javax_annotation_api_1_3_2.xml 611B
Maven__org_apache_tomcat_embed_tomcat_embed_el_9_0_14.xml 611B
Maven__org_springframework_spring_aop_5_1_4_RELEASE.xml 609B
Maven__org_springframework_spring_jcl_5_1_4_RELEASE.xml 609B
Maven__org_springframework_spring_web_5_1_4_RELEASE.xml 609B
Maven__org_apache_logging_log4j_log4j_to_slf4j_2_16_0.xml 608B
Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml 608B
Maven__org_springframework_spring_tx_5_1_4_RELEASE.xml 602B
Maven__com_fasterxml_jackson_core_jackson_core_2_9_8.xml 595B
Maven__mysql_mysql_connector_java_8_0_13.xml 574B
Maven__org_apache_logging_log4j_log4j_api_2_16_0.xml 573B
Maven__net_bytebuddy_byte_buddy_agent_1_9_7.xml 571B
Maven__org_apache_commons_commons_lang3_3_8_1.xml 570B
Maven__ch_qos_logback_logback_classic_1_2_3.xml 568B
Maven__org_hamcrest_hamcrest_library_1_3.xml 553B
Maven__org_mybatis_mybatis_spring_1_3_2.xml 549B
Maven__ch_qos_logback_logback_core_1_2_3.xml 547B
Maven__com_jayway_jsonpath_json_path_2_4_0.xml 546B
Maven__net_minidev_accessors_smart_1_2.xml 542B
Maven__org_aspectj_aspectjweaver_1_9_2.xml 542B
Maven__org_mockito_mockito_core_2_23_4.xml 542B
Maven__org_assertj_assertj_core_3_11_1.xml 542B
共 121 条
- 1
- 2
小七蒙恩
- 粉丝: 3957
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论10