Java & Backend · 2026 Edition

Top 50 Java Spring Boot & Microservices Interview Questions (2026 Edition)

·21 min read·Intervio Java Engineering Team

Key Takeaways — Spring Boot Interviews 2026

  • •Spring 6 & Boot 3 Standards: Mandatory migration to Java 17/21 baseline, Jakarta EE namespaces (jakarta.*), GraalVM Native Images (AOT compilation), and Virtual Threads (Project Loom) integration.
  • •IoC & Bean Lifecycle Internals: Deep understanding of ApplicationContext, Bean scopes (Singleton vs Prototype vs Request), @Autowired resolution, Circular Dependency handling, and BeanPostProcessor hooks.
  • •Microservices Resiliency: Resilience4j patterns (Circuit Breakers, Rate Limiter, Retry, Bulkhead), Spring Cloud Gateway routing, OpenTelemetry distributed tracing, and Saga pattern for distributed transactions.
  • •JPA & Transaction Management: Solving the Hibernate N+1 query problem using @EntityGraph or JOIN FETCH, and configuring @Transactional(propagation = Propagation.REQUIRES_NEW) boundaries.

1. Spring Core, Dependency Injection & Bean Lifecycle

The Inversion of Control (IoC) container is the backbone of the Spring framework. Interviewers frequently test what happens behind the scenes from application startup to bean destruction.

-- Complete Spring Bean Lifecycle Phases:
1. Instantiate Bean (Constructor Invocation)
2. Populate Properties (Dependency Injection / Field setting)
3. Set Aware Interfaces (BeanNameAware, BeanFactoryAware, ApplicationContextAware)
4. BeanPostProcessor.postProcessBeforeInitialization()
5. Initialization Callbacks (@PostConstruct, InitializingBean.afterPropertiesSet, custom init-method)
6. BeanPostProcessor.postProcessAfterInitialization() (AOP Proxy wrappers created here!)
7. Bean is ready for use in the ApplicationContext
8. Destruction Callbacks (@PreDestroy, DisposableBean.destroy, custom destroy-method)

Why is Constructor Injection preferred over Field Injection (@Autowired)?
Constructor injection guarantees immutability (fields can be declared final), prevents NullPointerException during unit testing without Spring context, and naturally prevents hidden circular dependencies by failing fast at startup.

2. Spring Boot 3 Internals: How @SpringBootApplication Works

@SpringBootApplication is a convenience meta-annotation combining three critical annotations:

  • @SpringBootConfiguration: A specialized form of @Configuration identifying the primary configuration class.
  • @EnableAutoConfiguration: Evaluates dependencies on the classpath and applies conditional auto-configurations (declared in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports).
  • @ComponentScan: Scans the current package and sub-packages for @Component, @Service, @Repository, @Controller beans.

3. Spring Data JPA, Hibernate & N+1 Problem Optimization

The Hibernate N+1 query problem occurs when fetching 1 parent entity causes Hibernate to execute N additional queries to fetch associated lazy child entities in a loop.

Solution 1: JPQL JOIN FETCH

@Query("SELECT u FROM User u JOIN FETCH u.orders WHERE u.status = :status")
List<User> findAllActiveUsersWithOrders(@Param("status") String status);

Solution 2: @EntityGraph

@EntityGraph(attributePaths = {"orders", "addresses"})
List<User> findByStatus(String status);

4. Microservices Architecture: Gateways, Resilience4j & Distributed Tracing

Microservices design questions test fault isolation across distributed networks:

Circuit Breaker (Resilience4j)

Transitions between CLOSED, OPEN, and HALF-OPEN states when downstream error rates exceed thresholds (e.g., 50%), returning fast fallbacks.

Saga Pattern (Choreography vs Orchestration)

Manages distributed transactions across microservices using compensating rollback transactions when a step in the business process fails.

5. Spring Security 6 & JWT Filter Chains

Spring Security 6 enforces component-based lambda DSL configuration without extending deprecated adapter classes:

SecurityFilterChain Bean

Defines stateless session management (SessionCreationPolicy.STATELESS), disables CSRF for REST APIs, and injects a custom OncePerRequestFilter (JwtAuthenticationFilter) before UsernamePasswordAuthenticationFilter.

SecurityContext & Authentication Tokens

Validates JWT signatures (HMAC-SHA256 / RSA), parses roles, and populates SecurityContextHolder.getContext().setAuthentication(authToken) for downstream endpoint authorization.

Practice Java & Spring Boot Technical Interviews

Simulate voice-based Java, Spring Boot, and Microservices interviews with Sophia AI. Instant real-time feedback on concurrency, JVM, JPA, and architecture trade-offs.

6. Frequently Asked Spring Boot Interview Questions

What is the difference between @Component, @Service, and @Repository?

All three are stereotypes of @Component. @Component is the generic base stereotype. @Service adds semantic clarity for business service layers without additional special behavior. @Repository decorates DAO classes and enables automatic translation of SQL exceptions into Spring's unified DataAccessException hierarchy.

How does Spring Boot 3 utilize Java 21 Virtual Threads?

By setting spring.threads.virtual.enabled=true in application.properties, Spring Boot 3 configures embedded Tomcat and async task executors to use lightweight JVM Virtual Threads instead of heavy OS threads, allowing servers to handle 10x–50x more concurrent blocking I/O requests with minimal memory overhead.

How do you solve the Hibernate N+1 query problem in Spring Data JPA?

The N+1 problem occurs when fetching a parent entity initiates N separate SQL queries for lazy-loaded children. The two industry-standard fixes are: (1) using JOIN FETCH in JPQL to eagerly load associations in a single SQL join query, and (2) applying @EntityGraph(attributePaths = {"items"}) above repository methods for clean declarative graph fetching without rewriting query strings.

How does Resilience4j Circuit Breaker transition between states?

Resilience4j operates in three primary states: CLOSED (normal operations, all calls routed to service), OPEN (failure rate threshold exceeded, all calls immediately fast-fail with CallNotPermittedException or execute a fallback), and HALF_OPEN (after a wait duration, a configurable probe trial evaluates whether the downstream service has recovered to close the circuit or reopen it).

What is the difference between @Transactional REQUIRED and REQUIRES_NEW?

Propagation.REQUIRED (default) joins an active transaction if one exists; otherwise, it spawns a new physical transaction. Propagation.REQUIRES_NEW unconditionally suspends the caller's active transaction and creates an entirely separate, independent physical database transaction. If the inner transaction commits, its changes persist even if the outer transaction subsequently rolls back.

How does Spring Boot auto-configuration work under the hood?

@SpringBootApplication enables @EnableAutoConfiguration, which reads candidate configuration classes from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Each auto-configuration class evaluates conditional annotations (e.g. @ConditionalOnClass, @ConditionalOnMissingBean, @ConditionalOnProperty) to dynamically instantiate beans only when required dependencies exist on the classpath.

Authoritative Citations & Technical References

The architectural principles, code standards, and patterns referenced in this guide are verified against official engineering specifications: