title: Use a different dataSource for quartz Scheduler that the one used in spring boot app
body: <p>I am working on spring boot application with the Quartz Scheduler.</p>
  <p>I have a application.properties and <code>quartz.properties</code> files where I configure my dataSource for each part.</p>
  <p>I use a Configuration File to configure a <code>SchedulerFactoryBean</code> with the application context so I can use <code>@Autowired</code> annotation for my services in quartz Job. But the <code>Datasource</code> for the scheduler is the <code>spring.datasource</code> and not the <code>org.quartz.datasource</code> set in the quartz properties file for the scheduler</p>
  <p>How can I set the <code>org.quartz.datasource</code> value only for my <code>SchedulerConfig</code> instead of the <code>spring.datasource</code> value ? or if it's not possible what would be the best practice to set up a different dataSource for my Quartz scheduler?</p>
  <p>Thanks in advance</p>
  <p>Code :</p>
  <p>Application properties</p>
  <pre><code># application.properties
      
  spring.quartz.job-store-type=jdbc
  spring.quartz.jdbc.initialize-schema=always
  
  spring.datasource.url = jdbc:postgresql://databaseUrl
  spring.datasource.username=myUsername
  spring.datasource.password=myPassword
  spring.datasource.driver-class-name.1=org.postgresql.Driver
  spring.jpa.hibernate.ddl-auto=create
  spring.security.basic.enable=false
  </code></pre>
  <p>Quartz.properties</p>
  <pre><code># Quartz.properties
  
  org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
  org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
  org.quartz.jobStore.tablePrefix = qrtz_
  org.quartz.jobStore.dataSource = quartzDataSource
  org.quartz.dataSource.quartzDataSource.driver = org.postgresql.Driver
  org.quartz.dataSource.quartzDataSource.URL = jdbc:postgresql://QuartzDatabaseUrl
  org.quartz.dataSource.quartzDataSource.user = myUser
  org.quartz.dataSource.quartzDataSource.password = myPassword
  org.quartz.jdbc.initialize-schema=always
  org.quartz.scheduler.classLoadHelper.class=org.quartz.simpl.ThreadContextClassLoadHelper
  org.quartz.dataSource.quartzDataSource.provider = hikaricp
  </code></pre>
  <p>SchedulerConfig.java :</p>
  <pre class="lang-java prettyprint-override"><code>// SchedulerConfig.java
  
  @Configuration
  public class SchedulerConfig {
  
      @Autowired
      private DataSource dataSource;
  
      @Autowired
      private ApplicationContext applicationContext;
  
      @Autowired
      private QuartzProperties quartzProperties;
  
  
      @Bean
      public SchedulerFactoryBean schedulerFactoryBean() {
  
          SchedulerJobFactory jobFactory = new SchedulerJobFactory();
          jobFactory.setApplicationContext(applicationContext);
  
          Properties properties = new Properties();
          properties.putAll(quartzProperties.getProperties());
  
          SchedulerFactoryBean factory = new SchedulerFactoryBean();
          factory.setOverwriteExistingJobs(true);
          factory.setDataSource(dataSource);
          factory.setQuartzProperties(properties);
          factory.setJobFactory(jobFactory);
          return factory;
      }
  }
  </code></pre>