Skip to content

Java and Spring Boot

Scope: back-end services and web applications built with Spring Boot 4 on a Java LTS release, with Spring Security, and Spring Data JPA and Hibernate for relational data. On 2026-12-03, Spring Boot 4.2 (released on 30 November 2026), 4.1 and 4.0 have open-source support, 4.0 until 31 December 2026; they run on Spring Framework 7 and need Java 17 or later. For configuration, health checks, telemetry and resilience, follow general/operations-reliability.md; for secrets, authorization and the supply chain, general/security.md; for sign-in and sessions, general/authentication.md; for data ownership, migrations and messaging, general/data.md; for architecture tests, general/testing-delivery.md. Container images, Kubernetes, telemetry pipelines and PostgreSQL have their own folders: Docker, Kubernetes, OpenTelemetry and PostgreSQL. The rules here cover what is specific to Spring Boot.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

  • 9 Spring Boot reference documentation (Spring): the baseline. Code structure, dependency injection, externalized configuration, profiles, data access, web and security, Actuator, observability, testing, packaging and deployment, with how-to guides for common tasks.
  • 8 Spring Security reference (Spring): the baseline for security: the filter chain architecture, authentication, request and method authorization, and protection against exploits such as CSRF.
  • 8 Spring Modulith reference (Spring): application modules in a Spring Boot application, verifying their structure, events between modules, module integration tests and documentation. Use it for modular monoliths.
  • 8 A Short Guide to Hibernate 7 (Hibernate): mapping entities and associations, sessions and transactions, queries, and tuning performance, including association fetching and the N+1 selects problem. Spring Boot 4.1 uses Hibernate 7.4.
  • 7 Spring Framework reference (Spring): the core container and dependency injection, transaction management, and the web frameworks that Spring Boot configures.
  • 7 Spring Data JPA reference (Spring): repositories, query methods, projections, entity graphs and transactionality.
  • 7 Spring Boot support timeline and support policy (Spring): the open-source and commercial support end date of each Spring Boot generation, and how long major and minor releases are supported.

Key rules

Structure and dependency injection

Configuration

  • 9 SPRING-3 Keep secrets out of application.properties, application.yaml and every other file in the repository: mount them as files and import them with spring.config.import=configtree:, or load them from a secrets manager, for example with Spring Cloud Vault. Spring Boot has no built-in encryption for property values. This is how Spring Boot applications follow SEC-2 in general/security.md. (Spring Boot, Using Configuration Trees, Encrypting Properties)
  • 6 SPRING-4 Bind your own settings to @ConfigurationProperties classes instead of scattering @Value annotations, and annotate them with @Validated and Jakarta Bean Validation constraints, so that Spring Boot validates the values when it binds them. @ConfigurationProperties adds full relaxed binding and configuration metadata, and gives the code one structured, type-safe object to inject. (Spring Boot, @ConfigurationProperties vs. @Value, @ConfigurationProperties Validation)

Security

  • 9 SPRING-5 Declare the authorization of every request in each SecurityFilterChain: permit the public paths explicitly, require roles or authorities for the rest, and end with anyRequest().authenticated() or anyRequest().denyAll(). Spring Security calls denying by default a healthy practice, because it turns the rules into an allow list. A custom SecurityFilterChain replaces Spring Boot's default web security, including the protection of Actuator endpoints, so it has to cover every request. Permit static resources with permitAll() rather than ignoring them, so that they still get security headers. This applies SEC-1 in general/security.md. (Spring Security, Authorize HttpServletRequests: matching by HTTP method, Favor permitAll over ignoring, Spring Boot, MVC Security)
  • 9 SPRING-6 Expose only the Actuator endpoints you need over HTTP, and secure every exposed endpoint other than health, with Spring Security rules built on EndpointRequest or by keeping the endpoints behind a firewall. Only health is exposed by default, because endpoints can contain sensitive information, and the Spring Boot docs strongly recommend securing the endpoints of a publicly exposed application. (Spring Boot, Exposing Endpoints, Actuator Security)
  • 8 SPRING-7 Keep Spring Security's CSRF protection, which is on by default, for every endpoint that browsers call with cookies or HTTP Basic credentials, and exempt only paths that only non-browser clients call, such as APIs authenticated with bearer tokens, with csrf.ignoringRequestMatchers() instead of turning the protection off with csrf.disable(). This applies AUTH-17, which also asks for GET, HEAD and OPTIONS requests without side effects. (Spring Security, When to use CSRF protection, CSRF and stateless browser applications, Safe methods must be read-only, Disable CSRF protection)
  • 7 SPRING-8 Use method security (@EnableMethodSecurity with @PreAuthorize and @PostAuthorize) for checks that depend on a method's arguments or return value, such as ownership of a record, and keep a catch-all rule in the SecurityFilterChain. Methods without an annotation aren't secured, and Spring Boot doesn't enable method security for you. (Spring Security, Method Security, Comparing request-level and method-level authorization)

Data

Operations

  • 7 SPRING-12 On Kubernetes, point the liveness and readiness probes at /actuator/health/liveness and /actuator/health/readiness, keep checks of external systems out of the liveness group, and give the pod a preStop sleep and a termination grace period long enough for the sleep and spring.lifecycle.timeout-per-shutdown-phase. Graceful shutdown is on by default, but traffic can still reach a pod that has begun shutting down. If Actuator runs on a separate management port, also expose the probes on the main port with management.endpoint.health.probes.add-additional-paths=true. This applies K8S-2 and K8S-3 in Kubernetes. (Spring Boot, Kubernetes Probes, Checking External State With Kubernetes Probes, Graceful Shutdown, Kubernetes Container Lifecycle)
  • 7 SPRING-13 Instrument through Micrometer Observation, which Spring Boot uses for metrics and traces, export both over OTLP to an OpenTelemetry Collector, and set the service name with OTEL_SERVICE_NAME or management.opentelemetry.resource-attributes. Add spring-boot-starter-opentelemetry for traces, and Micrometer's OTLP registry for metrics. Spring Boot samples only 10% of traces by default, so set management.tracing.sampling.probability deliberately (OTEL-8). The OpenTelemetry Java agent and Spring Boot starter, maintained by the OpenTelemetry community, are the alternatives. This applies OPS-11 in general/operations-reliability.md, and OTEL-1 and OTEL-11 in OpenTelemetry. (Spring Boot, Observability: OpenTelemetry Support, Tracing: OpenTelemetry With OTLP, Tracing: Sampling, Metrics: OTLP)

Versions and runtime

  • 8 SPRING-14 Run a Spring Boot generation that still has open-source support, and upgrade to the next minor release before its support ends; run it on a Java LTS release that your JDK distribution still updates. Each Spring Boot minor release gets at least 13 months of open-source support; for example, open-source support for Spring Boot 3.5 ended on 30 June 2026, and for 4.0 it ends on 31 December 2026. Java 17, 21 and 25 are LTS releases, and Spring Boot 4.1 runs on Java 17 to 27. This is how Spring Boot applications follow SEC-17 in general/security.md. (Spring, Spring Boot support timeline, Spring support policy, Spring Boot, System Requirements, Oracle Java SE Support Roadmap)
  • 5 SPRING-15 Enable virtual threads with spring.threads.virtual.enabled=true only on Java 21 or later, preferably Java 24 or later, and when you do, set spring.main.keep-alive=true and limit concurrency with semaphores or connection pools rather than pools of threads. Virtual threads are daemon threads, so scheduled tasks alone no longer keep the JVM running, and thread pool settings stop having an effect. Watch for pinned virtual threads, which lower throughput. (Spring Boot, Virtual threads, Oracle, Java 25 Virtual Threads)

Testing

  • 7 SPRING-16 Test controllers with @WebMvcTest and repositories with @DataJpaTest, and run at least the repository and integration tests against the database engine you use in production, started by Testcontainers and connected with @ServiceConnection. Each test slice loads only the configuration for one layer, so the tests stay fast. In-memory databases are fast, but the Hibernate guide advises testing against the database system you use in production. (Spring Boot, Auto-configured Tests, Testcontainers: Service Connections, Hibernate, Testing persistence logic)

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

Tutorials and further reading

  • 6 Developing Your First Spring Boot Application (Spring Boot docs): the official tutorial, from the build file to a running web application and an executable jar.
  • 6 Spring guides (Spring): short getting-started guides and tutorials for tasks such as building REST services, securing web applications, and accessing data with JPA.
  • 5 Spring PetClinic (Spring): the reference sample application, with Spring Boot, Spring Data JPA and tests.