Home › Spring Boot @Scheduled Generator

Spring Boot @Scheduled Cron Expression Generator

Generate cron expressions for Spring Boot @Scheduled(cron = "...") annotations online. Spring uses a 6-field format with seconds as the first field, based on the Quartz cron syntax.

Spring Boot @Scheduled Cron Generator

Spring cron uses 6 fields: second minute hour day month weekday. The day-of-week and day-of-month conflict is handled with ? - if you set a specific weekday, day must be * or ?.

Quick presets

0 * * * * ?

Runs every minute

Use in Spring Boot @Scheduled

@Scheduled annotation:

@Component
public class MyScheduledTask {

    @Scheduled(cron = "0 * * * * ?")
    public void runTask() {
        // task logic here
    }
}

Using a property (recommended for production):

@Scheduled(cron = "${my.task.cron}")
public void runTask() { ... }

In application.properties:

my.task.cron=0 * * * * ?

@Scheduled Cron vs Fixed Rate

@Scheduled accepts three different attributes - they are not interchangeable. Picking the wrong one is the most common Spring scheduling mistake.

AttributeMeaningExample
cronCalendar-based schedule, like crontabcron = "0 0 9 * * MON-FRI"
fixedRateRun every N ms, measured from start to startfixedRate = 5000
fixedDelayRun every N ms, measured from end to next startfixedDelay = 5000

Use cron whenever you need a specific time of day or day of week - the other two only express simple repeating intervals from app startup, not wall-clock time.

Spring vs Linux Cron

FeatureLinuxSpring Boot
Fields56
Field ordermin hr dom month dowsec min hr dom month dow
SecondsNoYes (1st field)
? operatorNoYes
L operatorNoYes
TimezoneServer TZApp TZ (configurable)

@Scheduled Setup Tips

Enable scheduling first

@Scheduled does nothing on its own. Add @EnableScheduling to your main class or a configuration class, or the annotation is silently ignored:

@SpringBootApplication
@EnableScheduling
public class MyApp { ... }

Set timezone per task

Available from Spring 5.3+:

@Scheduled(cron = "0 0 9 * * MON-FRI",
           zone = "Europe/Madrid")
public void morningTask() { ... }

Use properties, not hardcoded values

Hardcoding cron expressions in annotations makes them impossible to change without redeployment. Use ${property.name} so you can change the schedule via application.properties or environment variables. See the Spring @Scheduled Javadoc.

@Scheduled methods must return void

A scheduled method's return value is always ignored, since nothing is waiting to receive it. Methods must also take no arguments - Spring has nothing to pass in.

Spring Batch scheduled jobs

For Spring Batch, trigger a JobLauncher from a @Scheduled method. Same cron syntax applies - 6 fields, seconds first.

Spring Boot Cron Expression Examples

ExpressionDescription
0 * * * * ?Every minute at second 0
0 */5 * * * ?Every 5 minutes
0 0 * * * ?Every hour on the hour
0 0 0 * * ?Every day at midnight
0 0 9 * * MON-FRIWeekdays at 9:00 AM
0 0 0 1 * ?First of every month at midnight
0 0 0 L * ?Last day of every month
0 30 8 * * MONEvery Monday at 8:30 AM
0 0 6,18 * * ?Twice daily at 6 AM and 6 PM
0 0 0 ? * 2#1First Monday of every month