Skip to content

Identifying the bootstrap mode of a Spring Boot application #46368

@ThomasVitale

Description

@ThomasVitale

It's common to define special behaviour of a Spring Boot application based on whether it's run in development or when running tests. It would be great if Spring Boot itself would introduce a way to identify the bootstrap mode of an application:

  • dev mode, when running the application as part of a development workflow (e.g. from Gradle's bootRun, bootTestRun, or from an IDE)
  • test mode, when running auto tests
  • prod mode (the default one) in all other cases (e.g. when the application runs from a JAR or a container image).

This feature would enable several other features:

There are common configurations applied in most Spring Boot projects, enabled only during development. For example, exposing all Spring Boot Actuator endpoints and making them available without authentication. It would be so useful to have that out-of-the-box whenever the application is started in dev mode. Similarly, it would be possible to start introducing a series of features aimed at improving the developer experience. For example, replacing the whitelabel error page that is so often source of confusion in developers new to Spring Boot with some useful Spring Boot landing page. Or a more useful 404 page when in dev mode (see #5545). All these features could be implemented by third parties, but the bootstrap mode detection is something that cannot be done easily by a third party without affecting the developer experience.

The Spring Boot Gradle and Maven plugins could be extended to define a certain property signalling the bootstrap mode, based on which task/goal is executed.

I tried to determine the bootstrap mode inspired by the approach used in Spring Boot DevTools, but the implementation won't be as robust as if Spring Boot itself defined such feature in its core. I used the bootstrap mode determined in that way to define profiles that enhance the developer experience (see Arconia Profiles) and for applying some customisations to Testcontainers when in dev mode (see Arconia Dev Services).

I'm available to help in any way I can regarding this feature proposal.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions