The English version of is the official project site. Translated sites are community supported on a best-effort basis.

Quarkus Extension for Spring Scheduling API

While users are encouraged to use regular Quarkus scheduler, Quarkus provides a compatibility layer for Spring Scheduled in the form of the spring-scheduled extension.

This guide explains how a Quarkus application can leverage the well known Spring Scheduled annotation to configure and schedule tasks.


Para concluir este guia, você precisa:

  • Cerca de 15 minutos

  • Um IDE

  • JDK 11+ instalado com 'JAVA_HOME' configurado adequadamente

  • Apache Maven 3.9.5

  • Opcionalmente, o Quarkus CLI se você quiser usá-lo

  • Opcionalmente, Mandrel ou GraalVM instalado e configurado apropriadamente se você quiser criar um executável nativo (ou Docker se você usar uma compilação de contêiner nativo)

  • Some familiarity with the Spring Web extension


We recommend that you follow the instructions in the next sections and create the application step by step. However, you can go right to the completed example.

Clone the Git repository: git clone, or download an archive.

The solution is located in the spring-scheduled-quickstart directory.

Creating the Maven project

First, we need a new project. Create a new project with the following command:

quarkus create app org.acme:spring-scheduler-quickstart \
    --extension='resteasy-reactive,spring-scheduled' \
cd spring-scheduler-quickstart

Para criar um projeto Gradle, adicione a opção --gradle ou --gradle-kotlin-dsl.

Para obter mais informações sobre como instalar e usar a CLI do Quarkus, consulte o guia Quarkus CLI.

mvn io.quarkus.platform:quarkus-maven-plugin:3.5.3:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=spring-scheduler-quickstart \
    -Dextensions='resteasy-reactive,spring-scheduled' \
cd spring-scheduler-quickstart

Para criar um projeto Gradle, adicione a opção '-DbuildTool=gradle' ou '-DbuildTool=gradle-kotlin-dsl'.

Para usuários do Windows:

  • Se estiver usando cmd, (não use barra invertida '\' e coloque tudo na mesma linha)

  • Se estiver usando o Powershell, envolva os parâmetros '-D' entre aspas duplas, por exemplo, '"-DprojectArtifactId=spring-scheduler-quickstart"'

This command generates a Maven project with the spring-scheduled extension.

If you already have your Quarkus project configured, you can add the spring-scheduled extension to your project by running the following command in your project base directory:

quarkus extension add spring-scheduled
./mvnw quarkus:add-extension -Dextensions='spring-scheduled'
./gradlew addExtension --extensions='spring-scheduled'

This will add the following to your build file:


Creating a scheduled job

In the org.acme.spring.scheduler package, create the CounterBean class, with the following content:

package org.acme.spring.scheduler;

import org.springframework.scheduling.annotation.Scheduled;

import java.util.concurrent.atomic.AtomicInteger;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped              (1)
public class CounterBean {

    private AtomicInteger counter = new AtomicInteger();

    public int get() {   (2)
        return counter.get();

    @Scheduled(cron="*/5 * * * * ?")   (3)
    void cronJob() {
        counter.incrementAndGet();      (4)
        System.out.println("Cron expression hardcoded");

    @Scheduled(cron = "{cron.expr}")   (5)
    void cronJobWithExpressionInConfig() {
        System.out.println("Cron expression configured in");

    @Scheduled(fixedRate = 1000)    (6)
    void jobAtFixedRate() {
        System.out.println("Fixed Rate expression");

    @Scheduled(fixedRateString = "${fixedRate.expr}")      (7)
    void jobAtFixedRateInConfig() {
        System.out.println("Fixed Rate expression configured in");
1 Declare the bean in the application scope. Spring only detects @Scheduled annotations in beans.
2 The get() method allows retrieving the current value.
3 Use the Spring @Scheduled annotation with a cron-like expression to instruct Quarkus to schedule this method run. In this example we’re scheduling a task to be executed at 10:15am every day.
4 The code is pretty straightforward. Every day at 10:15am, the counter is incremented.
5 Define a job with a cron-like expression cron.expr which is configurable in
6 Define a method to be executed at a fixed interval of time. The period is expressed in milliseconds.
7 Define a job to be executed at a fixed interval of time fixedRate.expr which is configurable in

Updating the application configuration file

Edit the file and add the cron.expr and the fixedRate.expr configuration:

# The syntax used by Spring for cron expressions is the same as which is used by regular Quarkus scheduler.
cron.expr=*/5 * * * * ?

Creating the resource and the test

Create the CountResource class with the following content:

package org.acme.spring.scheduler;

import jakarta.inject.Inject;

public class CountResource {

    CounterBean counter;    (1)

    public String hello() {
        return "count: " + counter.get();   (2)
1 Inject the CounterBean
2 Send back the current counter value

We also need to update the tests. Edit the CountResourceTest class to match:

package org.acme.spring.scheduler;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

public class CountResourceTest {

    public void testHelloEndpoint() {
                .body(containsString("count"));  (1)

1 Ensure that the response contains count

Package and run the application

Run the application with:

quarkus dev
./mvnw quarkus:dev
./gradlew --console=plain quarkusDev

In another terminal, run curl localhost:8080/count to check the counter value. After a few seconds, re-run curl localhost:8080/count to verify the counter has been incremented.

Observe the console to verify that the following messages has been displayed: - Cron expression hardcoded - Cron expression configured in - Fixed Rate expression - Fixed Rate expression configured in These messages indicate that the executions of methods annotated with @Scheduled have been triggered.

As usual, the application can be packaged using:

quarkus build
./mvnw install
./gradlew build

And executed using java -jar target/quarkus-app/quarkus-run.jar.

You can also generate the native executable with:

quarkus build --native
./mvnw install -Dnative
./gradlew build -Dquarkus.package.type=native

Using Property Expressions

Quarkus supports the use of property expressions in the file so to externalize the configuration of the tasks you should store the properties in the file and use the fixedRateString, initialDelayString params respectively.

Note that this configuration is a build time configuration, the property expression will be resolved at build time.

Unsupported Spring Scheduled functionalities

Quarkus currently only supports a subset of the functionalities that Spring @Scheduled provides with more features being planned. Currently, the fixedDelay and fixedDelayString parameters are not supported, in other words, @Scheduled methods are always executed independently.

Important Technical Note

Please note that the Spring support in Quarkus does not start a Spring Application Context nor are any Spring infrastructure classes run. Spring classes and annotations are only used for reading metadata and / or are used as user code method return types or parameter types. What that means for end users, is that adding arbitrary Spring libraries will not have any effect. Moreover, Spring infrastructure classes (like org.springframework.beans.factory.config.BeanPostProcessor for example) will not be executed.

Related content