Create spring-boot-quartz module

Issue: 46107
This commit is contained in:
Stéphane Nicoll 2025-03-24 16:05:11 +01:00 committed by Phillip Webb
parent 1157dc5451
commit 8f623e8934
29 changed files with 96 additions and 42 deletions

View File

@ -93,6 +93,7 @@ include "spring-boot-project:spring-boot-mail"
include "spring-boot-project:spring-boot-mustache"
include "spring-boot-project:spring-boot-parent"
include "spring-boot-project:spring-boot-pulsar"
include "spring-boot-project:spring-boot-quartz"
include "spring-boot-project:spring-boot-r2dbc"
include "spring-boot-project:spring-boot-reactor-netty"
include "spring-boot-project:spring-boot-rsocket"

View File

@ -51,6 +51,7 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-liquibase"))
optional(project(":spring-boot-project:spring-boot-mail"))
optional(project(":spring-boot-project:spring-boot-neo4j"))
optional(project(":spring-boot-project:spring-boot-quartz"))
optional(project(":spring-boot-project:spring-boot-r2dbc"))
optional(project(":spring-boot-project:spring-boot-reactor-netty"))
optional(project(":spring-boot-project:spring-boot-tomcat"))

View File

@ -29,8 +29,8 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.quartz.autoconfigure.QuartzAutoConfiguration;
import org.springframework.context.annotation.Bean;
/**

View File

@ -164,7 +164,6 @@ dependencies {
optional("org.opensaml:opensaml-core:4.0.1")
optional("org.opensaml:opensaml-saml-api:4.0.1")
optional("org.opensaml:opensaml-saml-impl:4.0.1")
optional("org.quartz-scheduler:quartz")
optional("org.springframework:spring-aspects")
optional("org.springframework:spring-jdbc")
optional("org.springframework:spring-jms")

View File

@ -760,17 +760,6 @@
"level": "error"
}
},
{
"name": "spring.quartz.jdbc.comment-prefix",
"defaultValue": [
"#",
"--"
]
},
{
"name": "spring.quartz.scheduler-name",
"defaultValue": "quartzScheduler"
},
{
"name": "spring.reactor.stacktrace-mode.enabled",
"description": "Whether Reactor should collect stacktrace information at runtime.",

View File

@ -13,5 +13,4 @@ org.springframework.boot.autoconfigure.web.servlet.JspTemplateAvailabilityProvid
# Depends on Database Initialization Detectors
org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\
org.springframework.boot.autoconfigure.quartz.SchedulerDependsOnDatabaseInitializationDetector,\
org.springframework.boot.autoconfigure.session.JdbcIndexedSessionRepositoryDependsOnDatabaseInitializationDetector

View File

@ -55,7 +55,6 @@ org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration
org.springframework.boot.autoconfigure.netty.NettyAutoConfiguration
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration
org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration

View File

@ -2023,6 +2023,7 @@ bom {
"spring-boot-neo4j",
"spring-boot-properties-migrator",
"spring-boot-pulsar",
"spring-boot-quartz",
"spring-boot-r2dbc",
"spring-boot-reactor-netty",
"spring-boot-rsocket",

View File

@ -104,6 +104,7 @@ dependencies {
autoConfiguration(project(path: ":spring-boot-project:spring-boot-mustache", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-neo4j", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-pulsar", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-quartz", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-r2dbc", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-reactor-netty", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-rsocket", configuration: "autoConfigurationMetadata"))
@ -144,6 +145,7 @@ dependencies {
configurationProperties(project(path: ":spring-boot-project:spring-boot-mustache", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-neo4j", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-pulsar", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-quartz", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-r2dbc", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-reactor-netty", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-rsocket", configuration: "configurationPropertiesMetadata"))

View File

@ -37,18 +37,18 @@ To use a custom script, set the configprop:spring.quartz.jdbc.schema[] property.
Some of the standard scripts such as those for SQL Server, Azure SQL, and Sybase cannot be used without modification.
In these cases, make a copy of the script and edit it as directed in the script's comments then set configprop:spring.quartz.jdbc.schema[] to use your customized script.
To have Quartz use a javadoc:javax.sql.DataSource[] other than the application's main javadoc:javax.sql.DataSource[], declare a javadoc:javax.sql.DataSource[] bean, annotating its javadoc:org.springframework.context.annotation.Bean[format=annotation] method with javadoc:org.springframework.boot.autoconfigure.quartz.QuartzDataSource[format=annotation].
To have Quartz use a javadoc:javax.sql.DataSource[] other than the application's main javadoc:javax.sql.DataSource[], declare a javadoc:javax.sql.DataSource[] bean, annotating its javadoc:org.springframework.context.annotation.Bean[format=annotation] method with javadoc:org.springframework.boot.quartz.autoconfigure.QuartzDataSource[format=annotation].
Doing so ensures that the Quartz-specific javadoc:javax.sql.DataSource[] is used by both the javadoc:org.springframework.scheduling.quartz.SchedulerFactoryBean[] and for schema initialization.
Similarly, to have Quartz use a javadoc:org.springframework.transaction.TransactionManager[] other than the application's main javadoc:org.springframework.transaction.TransactionManager[] declare a javadoc:org.springframework.transaction.TransactionManager[] bean, annotating its javadoc:org.springframework.context.annotation.Bean[format=annotation] method with javadoc:org.springframework.boot.autoconfigure.quartz.QuartzTransactionManager[format=annotation].
Similarly, to have Quartz use a javadoc:org.springframework.transaction.TransactionManager[] other than the application's main javadoc:org.springframework.transaction.TransactionManager[] declare a javadoc:org.springframework.transaction.TransactionManager[] bean, annotating its javadoc:org.springframework.context.annotation.Bean[format=annotation] method with javadoc:org.springframework.boot.quartz.autoconfigure.QuartzTransactionManager[format=annotation].
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 configprop:spring.quartz.overwrite-existing-jobs[] property.
Quartz Scheduler configuration can be customized using `spring.quartz` properties and javadoc:org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer[] beans, which allow programmatic javadoc:org.springframework.scheduling.quartz.SchedulerFactoryBean[] customization.
Quartz Scheduler configuration can be customized using `spring.quartz` properties and javadoc:org.springframework.boot.quartz.autoconfigure.SchedulerFactoryBeanCustomizer[] beans, which allow programmatic javadoc:org.springframework.scheduling.quartz.SchedulerFactoryBean[] customization.
Advanced Quartz configuration properties can be customized using `spring.quartz.properties.*`.
NOTE: In particular, an javadoc:java.util.concurrent.Executor[] bean is not associated with the scheduler as Quartz offers a way to configure the scheduler through `spring.quartz.properties`.
If you need to customize the task executor, consider implementing javadoc:org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer[].
If you need to customize the task executor, consider implementing javadoc:org.springframework.boot.quartz.autoconfigure.SchedulerFactoryBeanCustomizer[].
Jobs can define setters to inject data map properties.
Regular beans can also be injected in a similar manner, as shown in the following example:

View File

@ -0,0 +1,45 @@
/*
* Copyright 2012-present 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "java-library"
id "org.springframework.boot.auto-configuration"
id "org.springframework.boot.configuration-properties"
id "org.springframework.boot.deployed"
id "org.springframework.boot.optional-dependencies"
}
description = "Spring Boot Quartz"
dependencies {
api(project(":spring-boot-project:spring-boot-tx"))
api("org.quartz-scheduler:quartz")
api("org.springframework:spring-context-support")
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-jpa"))
testImplementation(project(":spring-boot-project:spring-boot-flyway"))
testImplementation(project(":spring-boot-project:spring-boot-liquibase"))
testImplementation(project(":spring-boot-project:spring-boot-test"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testRuntimeOnly("ch.qos.logback:logback-classic")
testRuntimeOnly("com.h2database:h2")
testRuntimeOnly("com.zaxxer:HikariCP")
}

View File

@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
/**
* Define the supported Quartz {@code JobStore}.
*
* @author Stephane Nicoll
* @since 2.0.0
* @since 4.0.0
*/
public enum JobStoreType {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.util.Map;
import java.util.Properties;
@ -35,7 +35,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.autoconfigure.sql.init.OnDatabaseInitializationCondition;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@ -52,10 +51,10 @@ import org.springframework.transaction.PlatformTransactionManager;
*
* @author Vedran Pavic
* @author Stephane Nicoll
* @since 2.0.0
* @since 4.0.0
*/
@AutoConfiguration(after = DataSourceAutoConfiguration.class,
afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@AutoConfiguration(afterName = { "org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration",
"org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration" })
@ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
@EnableConfigurationProperties(QuartzProperties.class)
public class QuartzAutoConfiguration {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@ -31,7 +31,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
*
* @author Madhura Bhave
* @see QuartzDataSource
* @since 2.0.2
* @since 4.0.0
*/
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.util.List;
@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
* @author Vedran Pavic
* @author Andy Wilkinson
* @author Phillip Webb
* @since 2.6.0
* @since 4.0.0
*/
public class QuartzDataSourceScriptDatabaseInitializer extends DataSourceScriptDatabaseInitializer {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.time.Duration;
import java.util.ArrayList;
@ -31,7 +31,7 @@ import org.springframework.boot.sql.init.DatabaseInitializationMode;
*
* @author Vedran Pavic
* @author Stephane Nicoll
* @since 2.0.0
* @since 4.0.0
*/
@ConfigurationProperties("spring.quartz")
public class QuartzProperties {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@ -31,7 +31,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
*
* @author Andy Wilkinson
* @see QuartzDataSource
* @since 2.2.11
* @since 4.0.0
*/
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.util.Arrays;
import java.util.HashSet;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import javax.sql.DataSource;
@ -31,7 +31,7 @@ import org.springframework.scheduling.quartz.SchedulerFactoryBean;
* {@link QuartzDataSourceScriptDatabaseInitializer}.
*
* @author Vedran Pavic
* @since 2.0.0
* @since 4.0.0
*/
@FunctionalInterface
public interface SchedulerFactoryBeanCustomizer {

View File

@ -17,4 +17,4 @@
/**
* Auto-configuration for Quartz Scheduler.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;

View File

@ -0,0 +1,16 @@
{
"groups": [],
"properties": [
{
"name": "spring.quartz.jdbc.comment-prefix",
"defaultValue": [
"#",
"--"
]
},
{
"name": "spring.quartz.scheduler-name",
"defaultValue": "quartzScheduler"
}
]
}

View File

@ -0,0 +1,3 @@
# Depends on Database Initialization Detectors
org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\
org.springframework.boot.quartz.autoconfigure.SchedulerDependsOnDatabaseInitializationDetector

View File

@ -0,0 +1 @@
org.springframework.boot.quartz.autoconfigure.QuartzAutoConfiguration

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.quartz;
package org.springframework.boot.quartz.autoconfigure;
import java.io.InputStream;
import java.nio.file.Files;

View File

@ -22,7 +22,6 @@ description = "Starter for using the Quartz scheduler"
dependencies {
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
api(project(":spring-boot-project:spring-boot-quartz"))
api(project(":spring-boot-project:spring-boot-tx"))
api("org.springframework:spring-context-support")
api("org.quartz-scheduler:quartz")
}