eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

1. Introduction

Spring Boot applications can have complex component graphs, startup phases, and resource initialization steps.

In this article, we’ll take a look at how to track and monitor this startup information via a Spring Boot Actuator endpoint.

2. Application Startup Tracking

Tracking the various steps during application startup can provide useful information that can help us to understand the time spent during various phases of application startup. Such instrumentation can also improve our understanding of the context lifecycle and the application startup sequence.

The Spring Framework provides the functionality to record the application startup and graph initialization. In addition, Spring Boot Actuator provides several production-grade monitoring and management capabilities via HTTP or JMX.

As of Spring Boot 2.4, application startup tracking metrics are now available through the /actuator/startup endpoint.

3. Setup

To enable Spring Boot Actuator, let’s add the spring-boot-starter-actuator dependency to our POM:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

We’ll also add the spring-boot-starter-web dependency as this is required to access endpoints over HTTP:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>3.1.2</version>
</dependency>

In addition, we’ll also expose the required endpoint over HTTP by setting the configuration property in our application.properties file:

management.endpoints.web.exposure.include=startup

Finally, we’ll use curl and jq to query the actuator HTTP endpoint and parse the JSON response, respectively.

4. Actuator Endpoint

In order to capture startup events, we need to configure our application with an implementation of the @ApplicationStartup interface. By default, the ApplicationContext for managing the application lifecycle uses a no-op implementation. This obviously performs no startup instrumentation and tracking, for minimal overhead.

Therefore, unlike other actuator endpoints, we need some additional setup.

4.1. Using BufferingApplicationStartup

We need to set the application’s startup configuration to an instance of BufferingApplicationStartup. This is an in-memory implementation of the ApplicationStartup interface provided by Spring Boot. It captures the events during Spring’s startup process and stores them in an internal buffer.

Let’s start by creating a simple application with this implementation for our application:

@SpringBootApplication
public class StartupTrackingApplication {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(StartupTrackingApplication.class);
        app.setApplicationStartup(new BufferingApplicationStartup(2048));
        app.run(args);
    }
}

Here, we’ve also specified a capacity of 2048 for the internal buffer. Once the buffer reaches this capacity for events, no further data will be recorded. Therefore, it’s important that we use an appropriate value to allow storage of events based on the application complexity and the various steps executed during startup.

Crucially, the actuator endpoint is only available once this implementation is configured.

4.2. startup Endpoint

Now, we can start our application and query the startup actuator endpoint.

Let’s use curl to invoke this POST endpoint and format the JSON output using jq:

> curl 'http://localhost:8080/actuator/startup' -X POST | jq
{
  "springBootVersion": "2.5.4",
  "timeline": {
    "startTime": "2021-10-17T21:08:00.931660Z",
    "events": [
      {
        "endTime": "2021-10-17T21:08:00.989076Z",
        "duration": "PT0.038859S",
        "startTime": "2021-10-17T21:08:00.950217Z",
        "startupStep": {
          "name": "spring.boot.application.starting",
          "id": 0,
          "tags": [
            {
              "key": "mainApplicationClass",
              "value": "com.baeldung.startup.StartupTrackingApplication"
            }
          ],
          "parentId": null
        }
      },
      {
        "endTime": "2021-10-17T21:08:01.454239Z",
        "duration": "PT0.344867S",
        "startTime": "2021-10-17T21:08:01.109372Z",
        "startupStep": {
          "name": "spring.boot.application.environment-prepared",
          "id": 1,
          "tags": [],
          "parentId": null
        }
      },
      ... other steps not shown
      {
        "endTime": "2021-10-17T21:08:12.199369Z",
        "duration": "PT0.00055S",
        "startTime": "2021-10-17T21:08:12.198819Z",
        "startupStep": {
          "name": "spring.boot.application.running",
          "id": 358,
          "tags": [],
          "parentId": null
        }
      }
    ]
  }
}

As we can see, the detailed JSON response contains a list of instrumented startup events. It contains various details about each step such as the step name, start time, end time, as well as the step timing details. Detailed information about the response structure is available in the Spring Boot Actuator Web API documentation.

Additionally, the complete list of steps defined in the core container and further details about each step are available in Spring reference documentation.

An important detail to note here is that subsequent invocations of the endpoint do not provide a detailed JSON response. This is because the startup endpoint invocation clears the internal buffer. Therefore, we’ll need to restart the application to invoke the same endpoint and receive the full response again.

We should save the payload for further analysis if required.

4.3. Filtering Startup Events

As we’ve seen, the buffering implementation has a fixed capacity for storing events in memory. Therefore, it might not be desirable to store a large number of events in the buffer.

We can filter the instrumented events and only store those that may be of interest to us:

BufferingApplicationStartup startup = new BufferingApplicationStartup(2048);
startup.addFilter(startupStep -> startupStep.getName().matches("spring.beans.instantiate");

Here, we’ve used the addFilter method to only instrument steps with the specified name.

4.4. Custom Instrumentation

We can also extend BufferingApplicationStartup to provide custom startup tracking behavior to meet our specific instrumentation needs.

As this instrumentation is particularly valuable in testing environments rather than production, it’s a simple exercise to use a system property and switch between the no-op and buffering or custom implementations.

5. Analyzing Startup Times

As a practical example, let’s try to identify any bean instantiation during startup that might be taking a relatively long time to initialize. For example, this could be cache loading, database connection pooling, or some other expensive initialization during application startup.

We can invoke the endpoint as previously, but this time, we’ll process the output using jq.

As the response is quite verbose, let’s filter on steps that match the name spring.beans.instantiate and sort them by duration:

> curl 'http://localhost:8080/actuator/startup' -X POST \
| jq '[.timeline.events
 | sort_by(.duration) | reverse[]
 | select(.startupStep.name | match("spring.beans.instantiate"))
 | {beanName: .startupStep.tags[0].value, duration: .duration}]'

The above expression processes the response JSON to extract timing information:

  • Sort the timeline.events array in descending order.
  • Select all steps matching the name spring.beans.instantiate from the sorted array.
  • Create a new JSON object with beanName and the duration from each matching step.

As a result, the output shows a concise, ordered, and filtered view of the various beans instantiated during application startup:

[
  {
    "beanName": "resourceInitializer",
    "duration": "PT6.003171S"
  },
  {
    "beanName": "tomcatServletWebServerFactory",
    "duration": "PT0.143958S"
  },
  {
    "beanName": "requestMappingHandlerAdapter",
    "duration": "PT0.14302S"
  },
  ...
]

Here, we can see that the resourceInitializer bean is taking around six seconds during startup. This may be considered as contributing a significant duration to the overall application startup time. Using this approach, we can effectively identify this issue and focus on further investigation and possible solutions.

It’s important to note that ApplicationStartup is intended for use only during application startup. In other words, it does not replace Java profilers and metrics collection frameworks for application instrumentation.

6. Conclusion

In this article, we looked at how to obtain and analyze detailed startup metrics in a Spring Boot application.

First, we saw how to enable and configure the Spring Boot Actuator endpoint. Then, we looked at the useful information obtained from this endpoint.

Finally, we looked at an example to analyze this information in order to gain a better understanding of various steps during application startup.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)