Skip to main content

Spring

Set Up RMI and Hessian Remoting in Spring Boot 2

Learn how to configure Java RMI and Hessian remoting in Spring Boot 2 with RmiServiceExporter, HessianServiceExporter, and their proxy factory beans. Includes server and client configuration, shared interface setup, and a comparison table.

Creating Spring Beans with Static Factory Methods

Learn how to create Spring beans using static factory methods with @Bean configuration and XML. Covers third-party class registration, profile-based implementations, construction-time validation, and JUnit testing.

Top 40 Spring MVC Interview Questions and Answers (2025)

Prepare for your Java interview with the top 40 Spring MVC interview questions and answers covering DispatcherServlet, annotations, REST, validation, exception handling, and more — from beginner to advanced.

Building a REST API with Spring Boot: Complete Beginner's Guide

A complete beginner's guide to building a REST API with Spring Boot 3. Covers project setup, clean package structure, a Java record model with Bean Validation, a service layer, a @RestController with GET/POST/PUT/DELETE endpoints, global exception handling with @RestControllerAdvice, and end-to-end curl testing u2014 with fully annotated code throughout.

A Developer’s Guide to Testing Spring REST Clients with @RestClientTest

In modern microservices architecture, it's rare for a service to live in complete isolation. Most applications need to communicate with other services over the network, typically via REST APIs. When you build a component that consumes an external REST API, a critical question arises: how do you test it reliably without actually making network calls to a live, and potentially unstable, external service? This is where Spring Boot's test slices come to the rescue. For testing your REST clients, the framework provides a powerful and elegant solution: the @RestClientTest annotation. Let's dive deep into how you can use it to write clean, fast, and reliable tests for your HTTP client components. What Exactly is @RestClientTest? @RestClientTest is a "test slice" annotation specifically designed to test REST client components. Instead of loading your entire Spring application context (like @SpringBootTest does), it focuses only on the beans relevant to REST client operations. This makes your tests significantly faster and less prone to side effects from unrelated configurations. When you use @RestClientTest, Spring Boot will auto-configure the following for you: The Client Under Test: The specific REST client bean you want to test. MockRestServiceServer: A bean that lets you mock the server-side responses. You can instruct it: "When my client calls /api/employees/1, respond with this specific JSON." RestTemplateBuilder: Used to help construct RestTemplate instances. Jackson/Gson Support: It automatically includes support for serializing and deserializing JSON, so you can test your client-side data mapping. In short, it provides the perfect, minimal environment to verify that your client builds the correct HTTP request and correctly parses the HTTP response — all without a single packet leaving your machine.

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.

Building Native Images of Spring Boot Applications with GraalVM: A Step-by-Step Guide

In the ever-evolving landscape of cloud-native development and serverless architectures, the demand for applications with lightning-fast startup times and minimal memory footprints is greater than ever. Java, traditionally known for its "write once, run anywhere" philosophy, has sometimes faced criticism regarding these very aspects. However, with the advent of GraalVM and Spring Boot's dedicated support, Java is now a formidable contender in this space. This post will guide you through the process of building GraalVM native images of your Spring Boot native applications (specifically Spring Boot 3.x), demonstrating how to unlock significant optimizations in startup time and memory consumption, perfect for serverless Java and general cloud native Java deployments. Why Native Images? The GraalVM Advantage Traditional Java applications run on the Java Virtual Machine (JVM). While the JVM offers incredible runtime optimizations through its Just-In-Time (JIT) compiler, there's an inherent overhead: the JVM itself needs to start, classes need to be loaded, and code needs to be JIT-compiled at runtime. GraalVM Native Image technology compiles your Java application ahead-of-time (AOT) into a standalone executable. This executable includes the application code, required libraries, and a minimal runtime environment (the Substrate VM) – all compiled into a single binary. The benefits are substantial: Blazing Fast Startup: Native images typically start in milliseconds, making them ideal for serverless functions, microservices, and environments where rapid scaling is crucial. Reduced Memory Footprint: By eliminating the JVM overhead and only including the necessary code paths, native images use significantly less memory. Smaller Deployment Size: The resulting binary is often much smaller than a traditional JAR file bundled with a JRE. Lower Resource Consumption: Less CPU and memory usage translates to lower operational costs in cloud environments. Spring Boot 3.x has embraced GraalVM native image compilation with first-class support, making the process more seamless than ever.