spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
business:
url: jdbc:mysql://localhost:3306/auth?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: root
quartz:
url: jdbc:mysql://localhost:3306/au_scheduler?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: root
import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
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 javax.sql.DataSource;
@Slf4j
@Configuration
public class DataSourceConfig {
// 数据源配置的前缀,必须与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")
@ConfigurationProperties(prefix = BUSINESS_DATASOURCE_PREFIX)
public DruidDataSource druidDataSource() {
return new DruidDataSource();
}
/**
* @QuartzDataSource 注解则是配置Quartz独立数据源的配置
*/
@Bean("quartzDataSource")
@QuartzDataSource
@ConfigurationProperties(prefix = QUARTZ_DATASOURCE_PREFIX)
public DataSource quartzDataSource(){
return new DruidDataSource();
}
}
这是定时任务设置对于的数据源:
@Bean
public SchedulerFactoryBean getSchedulerFactoryBean(@Qualifier("quartzDataSource") DataSource dataSource) {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setAutoStartup(true);
schedulerFactoryBean.setDataSource(dataSource);
schedulerFactoryBean.setTriggers(configTriggersList());
return schedulerFactoryBean;
}

934

被折叠的 条评论
为什么被折叠?



