Skip to main content

Spring

Testing Spring REST Clients with @RestClientTest in Spring Boot 4.1

@RestClientTest and MockRestServiceServer, rebuilt against Spring Boot 4.1.1: a RestClient-based client, a legacy RestTemplate client, a declarative HTTP interface client, and the error path -- plus three real, verified surprises: two packages that moved without warning, Jackson 3 resolving in place of Jackson 2 by default, and a genuine trap where identical mocking code works for RestTemplate and throws a real AssertionError for RestClient.

Spring Security Context Propagation: The Complete Guide (With Virtual Threads & Structured Concurrency)

Spring Security's SecurityContext is the cornerstone of authentication and authorization in Spring applications, but propagating it across thread boundaries is a real trap in async, reactive, and now virtual-thread code. This guide covers ThreadLocal strategies, servlet and WebFlux propagation, @Async/ExecutorService/CompletableFuture, and—updated for Boot 4.1—virtual threads, DelegatingSecurityContextExecutor, ContextPropagatingTaskDecorator, and StructuredTaskScope, each verified against real, captured output.

Master Custom Authentication Providers in Spring Security 7.1

A from-scratch guide to writing a custom AuthenticationProvider in Spring Security 7.1 (Spring Boot 4.1): what actually wires an AuthenticationProvider bean into the AuthenticationManager, why the old manual ProviderManager pattern was never necessary, and how to run a custom provider alongside a JWT-secured API in the same application without the two colliding.

GraalVM Native Images for Spring Boot 4.1: The Reflection Trap, the Fix, and the Trap Inside the Fix

GraalVM native-image compiles a Spring Boot 4.1 app into a binary that starts in 0.09 seconds instead of 3.5 -- but only after a real ClassNotFoundException, a fix using the tracing agent, and a metadata-collision trap that silently undoes that fix. Rewritten with verified Boot 4.1.1 and current GraalVM versions, honest costs, and where Project Leyden fits as the non-native alternative.

Securing Spring MVC with SiteMinder Pre‑Authentication – A Step‑by‑Step Guide

Enterprise Java applications frequently live behind a corporate Single Sign-On (SSO) gateway such as Broadcom (formerly CA) SiteMinder. SiteMinder authenticates users at the reverse-proxy layer — before any request ever reaches your application server — and then injects the verified identity into a well-known HTTP request header (typically SM_USER). Your Spring Boot application simply trusts that header and builds a security context from it, with no login form and no password handling of its own. This pattern is called pre-authentication: the heavy lifting of credential verification is delegated to an external system, and your app only needs to map the already-authenticated identity to application-level roles. Spring Security has first-class support for this via RequestHeaderAuthenticationFilter and PreAuthenticatedAuthenticationProvider. This tutorial walks through a complete Spring Boot 3.x / Spring Security 6.x configuration, covering Maven dependencies, the security filter chain using the modern lambda DSL, a UserDetailsService implementation, and tips for testing locally without a real SiteMinder agent.

Virtual Threads on Spring Boot 4.1: The Benchmarks, Re-Run, and the Pinning Advice That Expired

If you enabled virtual threads on Spring Boot 3.4 sometime in the last year, you probably also copied in the standard advice that came with every article about them: avoid synchronized, because a virtual thread that blocks while holding a monitor pins its carrier thread, and watch for it with -Djdk.tracePinnedThreads=full. That advice was correct when it was written. On Spring Boot 4.1 and JDK 25, most of it is no longer true…

Spring Boot RestTemplate with Basic Auth: A Modern Guide

Basic Auth-secured microservice calls rebuilt on RestClient, Spring Boot 4's recommended HTTP client: two patterns ported from RestTemplate, the {noop} password myth corrected, and the RestClient.exchange() trap that silently swallows 401s.

Custom Validation in Spring Boot: Beyond the Basics!

A custom Bean Validation constraint built from scratch on Spring Boot 4.1.1 and Jakarta Validation 3.1: the javax→jakarta namespace fix Boot 3 already required, field- and class-level constraints on Java records, and what spring.mvc.problemdetails.enabled does and does not fix.

Building Your First Spring RESTful API: A “Hello World” Guide

Let's dive into the exciting world of Spring Boot and RESTful APIs. If you’re looking to build robust, scalable web services, Spring Boot is an excellent choice and understanding how to create a simple REST API is a fundamental first step. In this tutorial, we’ll walk through creating a “Hello World” RESTful service that exposes JSON data. This example will cover the basic setup of a Spring Boot project and demonstrating how to handle HTTP GET requests. Prerequisites Before we begin, make sure you have the following installed: Java Development Kit (JDK) 8 or higher: You can download it from the Oracle website. Apache Maven: For project management and dependency handling. Download from the Maven website. An Integrated Development Environment (IDE): IntelliJ IDEA, Eclipse, or VS Code with Java extensions are all great choices. Step 1: Create a Spring Boot Project The easiest way to start a Spring Boot project is by using the Spring Initializr. Go to the website and configure your project as follows: Project: Maven Project Language: Java Spring Boot: Choose the latest stable version (e.g., 2.7.x or 3.x.x) Group: com.ankurm.restapi Artifact: hello-world Name: hello-world Package name: com.ankurm.restapi.helloworld Packaging: Jar Java: 17 (or your preferred version) Dependencies: Add Spring Web Click “Generate” to download the project as a ZIP file. Extract it to your desired location.

A Practical Guide to Monitoring Spring Boot Microservices: Prometheus, Grafana, and Boot 4.1’s OpenTelemetry Starter

The original version of this post walked through building a Prometheus and Grafana stack by hand: add micrometer-registry-prometheus, expose /actuator/prometheus, run a Prometheus container with a hand-written scrape config, run a Grafana container, wire up a data source, import a dashboard by ID. None of that stopped working on Spring Boot 4.1 — it's still a completely valid way to run Prometheus and Grafana. What changed is that Boot 4.1 adds a fourth option, built by the Spring team, that skips almost all of it: point one Docker Compose file at a real observability backend and the metrics and traces just start arriving, verified end to end against a real running container, not a diagram.