Spring Boot

repository·main·Indexed 13 days ago

https://github.com/spring-projects/spring-boot

An opinionated framework for creating production-grade, Spring-powered applications and services. Includes the Spring Boot Gradle Plugin for packaging executable JAR/WAR files, dependency management via spring-boot-dependencies, and Spring AOT (Ahead-of-Time) processing for GraalVM native images. Supports Gradle 8.14+ and 9.x.

Tokens
148.2K
Snippets
486
Records
819
Agent score
95%

What's inside Spring Boot

  1. Overview of Spring Boot

    main

    Spring Boot is a framework designed to create stand-alone, production-grade Spring-based applications with minimal configuration. It takes an opinionated view of the Spring platform and third-party libraries to provide a fast getting-started experience while allowing for customization when requirements diverge from defaults.

    Key features include:

    • Deployment Options: Create Java applications that can be run via java -jar or through traditional WAR deployments.
    • Non-functional Features: Built-in support for embedded servers, security, metrics, health checks, and externalized configuration.
    • Developer Experience: No requirement for XML configuration and no code generation (except when targeting native images).
  2. Overview of Actuator Endpoints

    main

    Actuator endpoints allow you to monitor and interact with your running application. An endpoint is available when access is permitted and it is exposed. Most applications expose endpoints over HTTP, where the endpoint ID is mapped to a URL with an /actuator prefix (e.g., /actuator/health).

    Technology-Agnostic Endpoints

    • auditevents: Audit events information.
    • beans: List of all Spring beans.
    • caches: Available caches.
    • conditions: Configuration and auto-configuration evaluation results.
    • configprops: List of @ConfigurationProperties (subject to sanitization).
    • env: Properties from ConfigurableEnvironment (subject to sanitization).
    • flyway: Flyway database migrations.
    • health: Application health information.
    • httpexchanges: Last 100 HTTP request-response exchanges.
    • info: Arbitrary application info.
    • integrationgraph: Spring Integration graph.
    • loggers: View and modify logger configuration.
    • liquibase: Liquibase database migrations.
    • metrics: Application metrics.
    • mappings: List of @RequestMapping paths.
    • quartz: Quartz Scheduler jobs.
    • scheduledtasks: Scheduled tasks.
    • sessions: User sessions (requires Spring Session).
    • shutdown: Graceful shutdown (jar packaging only; disabled by default).
    • startup: Startup steps data (requires BufferingApplicationStartup).
    • threaddump: Performs a thread dump.

    Web-Specific Endpoints

    If your application is a web application (Spring MVC, WebFlux, or Jersey):

    • heapdump: Returns an HPROF (HotSpot) or PHD (OpenJ9) heap dump.
    • logfile: Returns log file contents (supports HTTP Range header).
    • prometheus: Metrics in Prometheus format (requires micrometer-registry-prometheus).
  3. Introduction to the Spring Boot Gradle Plugin

    main

    The Spring Boot Gradle Plugin integrates Spring Boot capabilities directly into the Gradle build system. It provides three core functionalities:

    1. Packaging: Create executable JAR or WAR archives for your Spring Boot applications.
    2. Execution: Run Spring Boot applications directly via Gradle tasks.
    3. Dependency Management: Automatically apply dependency management rules provided by spring-boot-dependencies to ensure compatible versions of Spring Boot libraries.

    Requirements & Compatibility:

    • Gradle Version: Requires Gradle 8.x (specifically 8.14 or later) or Gradle 9.x.
    • Configuration Cache: Compatible with Gradle's configuration cache.
  4. Overview of Spring Boot Build Tool Plugins

    main

    Spring Boot provides dedicated plugins for both Maven and Gradle to streamline the development lifecycle. These plugins primarily handle the packaging of executable JAR files and provide various lifecycle management features specific to Spring Boot applications.

    Before configuring specific plugin features, it is recommended to understand the general process of using build systems with Spring Boot by referring to the [Using Build Systems] guide.

  5. Use the Spring Boot Gradle Plugin

    main

    The Spring Boot Gradle Plugin integrates Spring Boot support into Gradle projects. It enables several core capabilities:

    • Packaging: Create executable JAR or WAR archives.
    • Execution: Run Spring Boot applications directly via Gradle tasks.
    • Dependency Management: Automatically use the dependency management provided by spring-boot-dependencies to ensure compatible versions of libraries.

    Requirements:

    • Gradle 8.x (specifically 8.14 or later) or Gradle 9.x.
    • Compatible with Gradle's configuration cache.
  6. Containerize Spring Boot applications

    main

    Spring Boot applications can be packaged into optimized, Docker-compatible container images using two primary methods:

    1. Dockerfiles: Manually defining the image structure and dependencies.
    2. Cloud Native Buildpacks: Automatically creating optimized images without needing to write a Dockerfile.

    These images can be run in any environment that supports Docker-compatible container runtimes.

  7. Packaging Spring Boot Applications

    main

    Spring Boot provides multiple technologies to optimize applications for deployment. Depending on your requirements for startup speed, memory footprint, or portability, you can package your application using one or more of the following methods:

    • GraalVM native images: For high-performance, low-memory footprint deployments.
    • AOT cache: To optimize Ahead-of-Time processing.
    • Checkpoint and Restore: For rapid application startup and state management.
    • Docker container images: For containerized deployments using various packaging techniques.
  8. Testing GraalVM Native Images

    main

    When developing native image applications, it is recommended to use the JVM for the majority of unit and integration tests to maintain fast build times and IDE support. Native image testing should focus on two specific areas:

    1. Spring AOT Engine: Ensuring the application can be processed and run in AOT-processed mode.
    2. GraalVM Hints: Ensuring GraalVM has sufficient hints to produce a valid native image.

    You can test using two primary approaches: testing AOT processing on the JVM or running tests directly inside a native image using Native Build Tools.