From c6fdb4f0f2244aa7d7c47cfc1c1ee70c6e5cf037 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 9 Oct 2018 15:05:25 +0100 Subject: [PATCH] Improve documentation of Quartz DataSource customization Closes gh-12780 --- .../autoconfigure/quartz/QuartzAutoConfiguration.java | 2 ++ .../quartz/SchedulerFactoryBeanCustomizer.java | 9 ++++++++- .../src/main/asciidoc/spring-boot-features.adoc | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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 59de80ab1d..7c220fa19a 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 @@ -40,6 +40,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; @@ -126,6 +127,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 c59634ed22..471711b5b2 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 @@ -5979,6 +5979,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. + Quartz Scheduler configuration can be customized by using Quartz configuration properties ()`spring.quartz.properties.*`) and `SchedulerFactoryBeanCustomizer` beans, which allow programmatic `SchedulerFactoryBean` customization.