What is ApplicationRunner in Spring Boot?

ApplicationRunner is a Spring Boot interface that allows developers to execute custom logic immediately after the Spring application context has been fully initialized and the application has started successfully. It is commonly used for startup tasks such as loading initial data, validating configurations, warming caches, or performing setup operations.

Key Points

Why Do We Need ApplicationRunner?

Sometimes applications need to perform tasks immediately after startup.

Examples

ApplicationRunner provides a clean and structured way to perform such operations.

How Does It Work?

Application Startup

|

Spring Context Initialization

|

Bean Creation

|

Application Ready

|

ApplicationRunner Executes

|

Application Starts Serving Requests

The run() method is called automatically once the application is fully initialized.

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class StartupRunner
        implements ApplicationRunner {

    @Override
    public void run(
            ApplicationArguments args)
            throws Exception {

        System.out.println(
                "Application Started Successfully");
    }
}

Output

Application Started Successfully

In this example

Accessing Startup Arguments

ApplicationRunner provides access to command-line arguments through the ApplicationArguments object.

@Component
public class StartupRunner
        implements ApplicationRunner {

    @Override
    public void run(
            ApplicationArguments args) {

        System.out.println(
                args.getOptionNames());
    }
}

Application Start

java -jar app.jar --env=prod

The argument can be accessed inside the run() method.

Common Use Cases

Example

Suppose an e-commerce application requires product categories to be loaded into memory.

At startup

ApplicationRunner vs CommandLineRunner

Spring Boot provides two startup interfaces.

ApplicationRunner

public void run(

ApplicationArguments args)

Benefits

CommandLineRunner

public void run(

String... args)

Benefits

Example

CommandLineRunner

public void run(

String... args)

ApplicationRunner

public void run(

ApplicationArguments args)

Most modern Spring Boot applications prefer ApplicationRunner because of its richer argument API.

Executing Multiple Runners

If multiple runners exist, execution order can be controlled.

@Component

@Order(1)
public class FirstRunner
        implements ApplicationRunner {

}

@Component

@Order(2)
public class SecondRunner
        implements ApplicationRunner {

}

Execution Order

FirstRunner

↓

SecondRunner

Real-World Example

Consider a banking application.

After startup

ApplicationRunner is an ideal place for these startup tasks.

Best Practices

Interview Tip

A concise interview answer is

ApplicationRunner is a Spring Boot interface used to execute custom code immediately after the application starts and the Spring context is fully initialized. It is commonly used for startup tasks such as loading initial data, validating configurations, warming caches, and processing startup arguments through the ApplicationArguments object.

Last updated: 11 November 2026

Previous question: What is autowiring in Spring?

Next question: What is CommandLineRunner in Spring Boot?

More Spring Boot - Level I interview questions

All Spring Boot - Level I questions