Best of BaeldungApril 2026

  1. 1
    Article
    Avatar of baeldungBaeldung·5w

    Introduction to Spring Data AOT Repositories

    Spring Data AOT Repositories is a new feature coming in Spring Boot 4 that shifts repository preparation from runtime to build time. Previously, Spring Data used runtime reflection and dynamic proxies to implement repository interfaces via SimpleJpaRepository. With AOT Repositories enabled, Spring generates concrete repository implementation classes (e.g., UserRepositoryImpl__AotRepository) at compile time, eliminating most runtime reflection and proxy overhead. The article walks through the evolution across three modes: no AOT, AOT without repository optimization, and full AOT Repositories. Performance benchmarks show startup time improvements (10.1s → 9.9s → 8.7s) and faster build times come at the cost of longer compile times (11s → 17s → 25s). A notable benefit is compile-time detection of JPA query errors. The feature is enabled by setting spring.aot.repositories.enabled=true alongside spring.aot.enabled=true.

  2. 2
    Article
    Avatar of baeldungBaeldung·6w

    Getting a Cron Expression From Database for a Spring Boot Scheduled Job

    Two approaches for loading cron expressions from a database in Spring Boot are compared. The first uses a Spring bean (cronLoader) referenced via SpEL in @Scheduled, which is simple but only reads the value once at startup. The second uses SchedulingConfigurer to register a trigger task that re-reads the cron expression from the database before each execution, enabling runtime schedule changes without restarting the application. An H2 in-memory database with JPA is used for demonstration, along with a REST endpoint to update the cron value on the fly.

  3. 3
    Article
    Avatar of baeldungBaeldung·7w

    Multi-Factor Authentication in Spring Security 7

    Spring Security 7 introduces native multi-factor authentication (MFA) support using a factor-based authority model. Each successful authentication step grants a FactorGrantedAuthority to the user's security context. The new @EnableMultiFactorAuthentication annotation enables MFA globally, while AuthorizationManagerFactory allows applying MFA rules to specific endpoints. The post covers global MFA setup, endpoint-specific rules, time-based re-authentication requirements, user-based conditional MFA, and unit testing MFA flows with Spring Security test utilities.

  4. 4
    Article
    Avatar of baeldungBaeldung·8w

    JMOD File Format in Java

    JMOD is a Java packaging format introduced with the Java Platform Module System (JPMS) in Java 9. Unlike JAR files, JMOD files are designed for compile and link time only — they cannot be placed on the classpath at runtime. They support native libraries, configuration files, and legal notices in addition to compiled classes. A practical walkthrough shows how to create a modular Java application, package it as a JMOD file using the `jmod create` command, and then use `jlink` to produce a custom minimal Java runtime image (~35 MB vs 400+ MB for a full JDK) containing only the required modules.