Springboot version 2.1.6 multi data source configuration using the druid configure a database for use Oracle11g, if you are using MySQL, and drive directly to the address database to change it
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.17</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
Two .Quartz Configuration Introduction
the Spring:
the DataSource:
of the type: com.alibaba.druid.pool.DruidDataSource
Driver-class-name: oracle.jdbc.driver.OracleDriver
Druid:
Business: # Configure business data source
url: jdbc: oracle: thin: @ 127.0.0.1: 1521: ORCL
username: Business
password: Business
Quartz: Quartz # configure data source
URL: JDBC: Oracle: Thin: @ 127.0.0.1: 1521: ORCL
username: Quartz
password: Quartz
# supplemented disposed below the connection pool, applied to the upper All the data source
# initial size, minimum, maximum
initialSize:. 5
minIdle:. 5
for maxActive: 15
# configuration obtaining connection waiting timeout time
maxWait: 60000
# intervals the frequency of such detection, the detection needs to close idle connections milliseconds
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: the SELECT the FROM. 1 the DUAL
testWhileIdle: to true
testOnBorrow: to false
testOnReturn: to false
# open PSCache, and specifies the size of each connection PSCache
poolPreparedStatements: to true
# configure the monitoring statistics intercepted filters, after removing the monitoring interface can not sql statistics, 'wall' firewalls
maxPoolPreparedStatementPerConnectionSize: 20 is
Filters: STAT, Wall, log4j2
# mergeSql opened by connectProperties property function; slow SQL record
connectionProperties: druid.stat.mergeSql = true; druid.stat.slowSqlMillis = 5000
monitor merging data # plurality of DruidDataSource
useGlobalDataSourceStat: to true
Remove-Abandoned: to true
Remove-Abandoned-timeout: 180 [
log-Abandoned: to true
Quartz:
JDBC:
initialize-schema: never # Configure whether each restart projects are automatically generated Quartz table structure, as used herein, can always be generated once after the change never configured
the Job-Store-of the type: jdbc
the Properties:
ORG:
the Quartz:
Scheduler:
instanceName: etlCleanScheduler
the instanceId: the AUTO
JobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
the tablePrefix: QRTZ_ #Quartz table prefix
isClustered: to true
clusterCheckinInterval: 10000
useProperties: to false
ThreadPool:
class: org.quartz .simpl.SimpleThreadPool
# thread a number of tasks using a thread
threadCount: 100
ThreadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: to true
III. Configure multiple sources of data
package com.rubikstack.etlclean.config;
import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.quartz.QuartzDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import tk.mybatis.spring.annotation.MapperScan;
import javax.sql.DataSource;
import java.util.Properties;
@Slf4j
@Configuration
@MapperScan(basePackages = DataSourceConfig.MAPPER_PACKAGE, sqlSessionFactoryRef = DataSourceConfig.SESSION_FACTORY)
public class DataSourceConfig {
@Value("${mybatis.queryLimit}")
private String queryLimit;
static final String SESSION_FACTORY = "dbSqlSessionFactory";
private static final String DATASOURCE_NAME = "dbDataSource";
/**
* mapper类的包路径
*/
static final String MAPPER_PACKAGE = "com.example.mapper";
static final String MODEL_PACKAGE = "com.example.model";
/**
* 自定义mapper的xml文件路径
*/
private static final String MAPPER_XML_PATH = "classpath*:com.example.mapper/*Mapper.xml";
/**
* 数据源配置的前缀,必须与application.properties中配置的对应数据源的前缀一致
*/
private static final String BUSINESS_DATASOURCE_PREFIX = "spring.datasource.druid.business";
private static final String QUARTZ_DATASOURCE_PREFIX = "spring.datasource.druid.quartz";
@Primary
@Bean(name = DATASOURCE_NAME)
@ConfigurationProperties(prefix = BUSINESS_DATASOURCE_PREFIX)
public DruidDataSource druidDataSource() {
return new DruidDataSource();
}
/**
* 配置Mybatis环境
*/
@Primary
@Bean(name = SESSION_FACTORY)
public SqlSessionFactory sqlSessionFactory() {
log.info("配置SqlSessionFactory开始");
final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(druidDataSource());
try {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// 自定义mapper的xml文件地址,当通用mapper提供的默认功能无法满足我们的需求时,可以自己添加实现,与mybatis写mapper一样
sessionFactoryBean.setMapperLocations(resolver.getResources(MAPPER_XML_PATH));
org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
Properties properties = new Properties();
properties.put("queryLimit",queryLimit);
configuration.setVariables(properties);
configuration.setMapUnderscoreToCamelCase(true);
configuration.setLogImpl(org.apache.ibatis.logging.stdout.StdOutImpl.class);
sessionFactoryBean.setConfiguration(configuration);
sessionFactoryBean.setTypeAliasesPackage(MODEL_PACKAGE);
return sessionFactoryBean.getObject();
} catch (Exception e) {
log.error("配置SqlSessionFactory失败,error:{}", e.getMessage());
throw new RuntimeException(e.getMessage());
}
}
/**
* @QuartzDataSource 注解则是配置Quartz独立数据源的配置
*/
@Bean
@QuartzDataSource
@ConfigurationProperties(prefix = QUARTZ_DATASOURCE_PREFIX)
public DataSource quartzDataSource(){
return new DruidDataSource();
}
}