spring mysql多数据源配置

spring mysql多数据源配置

 

@Configuration
public class QuartzConfig {

    @Autowired
    private AutowireJobFactory jobFactory;

    @Bean(name = "quartzDataSource")
    @ConfigurationProperties(prefix="spring.datasource.quartz")
    public DataSource quartzDataSource() {
        return DataSourceBuilder.create().build();
    }

    private Properties quartzProperties() {
        Properties properties = new Properties();
        properties.put("org.quartz.jobStore.tablePrefix", "DC_QRTZ_");
        return properties;
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setJobFactory(jobFactory);
        schedulerFactoryBean.setDataSource(quartzDataSource());
        schedulerFactoryBean.setQuartzProperties(quartzProperties());
        return schedulerFactoryBean;
    }

    @Bean
    public Scheduler scheduler() {
        return schedulerFactoryBean().getScheduler();
    }

}

 

application.properties

# quartz datasource
spring.datasource.quartz.url=jdbc:mysql://rds.aliyuncs.com:3306/iotx-data-center-meta
spring.datasource.quartz.username=dataservice
spring.datasource.quartz.password=Data12345
spring.datasource.quartz.driver-class-name=com.mysql.jdbc.Driver

 

posted @ 2017-12-29 11:59  穆穆兔兔  阅读(1364)  评论(0编辑  收藏  举报