diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java index 7e8f09bb00..de4e317823 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java @@ -39,6 +39,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; import org.springframework.core.io.ResourceLoader; import org.springframework.scheduling.quartz.SchedulerFactoryBean; import org.springframework.transaction.PlatformTransactionManager; @@ -132,6 +133,7 @@ public class QuartzAutoConfiguration { protected static class JdbcStoreTypeConfiguration { @Bean + @Order(0) public SchedulerFactoryBeanCustomizer dataSourceCustomizer( QuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider quartzDataSource, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/SchedulerFactoryBeanCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/SchedulerFactoryBeanCustomizer.java index f5c909623a..8a1d488f77 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/SchedulerFactoryBeanCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/SchedulerFactoryBeanCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,19 @@ package org.springframework.boot.autoconfigure.quartz; +import javax.sql.DataSource; + import org.springframework.scheduling.quartz.SchedulerFactoryBean; /** * Callback interface that can be implemented by beans wishing to customize the Quartz * {@link SchedulerFactoryBean} before it is fully initialized, in particular to tune its * configuration. + *

+ * For customization of the {@link DataSource} used by Quartz, use of + * {@link QuartzDataSource @QuartDataSource} is preferred. It will ensure consistent + * customization of both the {@link SchedulerFactoryBean} and the + * {@link QuartzDataSourceInitializer}. * * @author Vedran Pavic * @since 2.0.0 diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 6ab1bad2a7..832b0bf45b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -6253,6 +6253,11 @@ NOTE: By default, the database is detected and initialized by using the standard provided with the Quartz library. It is also possible to provide a custom script by setting the `spring.quartz.jdbc.schema` property. +To have Quartz use a `DataSource` other than the application's main `DataSource`, declare +a `DataSource` bean, annotating its `@Bean` method with `@QuartzDataSource`. Doing so +ensures that the Quartz-specific `DataSource` is used by both the `SchedulerFactoryBean` +and for schema initialization. + By default, jobs created by configuration will not overwrite already registered jobs that have been read from a persistent job store. To enable overwriting existing job definitions set the `spring.quartz.overwrite-existing-jobs` property.