Spring Boot Interview Questions With Practical Answers

Stackademic

Spring Boot interview questions on DI, REST, JPA, security, and testing—with answers that reflect how JVM services run in production.

Spring Boot interviews still test whether you understand how JVM services start, how dependencies wire together, and how production concerns (transactions, security, observability) show up in everyday code. Memorizing annotations helps, but interviewers listen for trade-offs: when @Transactional fails silently, why actuator endpoints need locking down, and how you would debug a slow startup.

This guide walks through questions that appear frequently for backend and platform roles, with answers grounded in how Spring Boot actually behaves—not textbook definitions alone.

What Spring Boot adds on top of Spring

Spring Boot autoconfigures common setups: embedded Tomcat or Jetty, Jackson for JSON, datasource pools, and Spring MVC or WebFlux. The @SpringBootApplication meta-annotation combines configuration, component scanning, and autoconfiguration enablement.

Interviewers often ask why Boot is not a separate framework. It is opinionated packaging around Spring Framework modules plus starters (spring-boot-starter-web, spring-boot-starter-data-jpa). Starters pull transitive dependencies with versions tested together by the Spring team.

Be ready to explain application.properties versus application.yml, profile-specific files (application-prod.yml), and externalized configuration through environment variables—12-factor style.

Core annotations and the application context

Common questions

  • Difference between @Component, @Service, @Repository, and @Controller
  • What @Autowired does and constructor injection versus field injection
  • How @Configuration and @Bean differ from stereotype annotations

Strong answer shape

Stereotypes mark classes for classpath scanning; semantics guide exception translation (@Repository) and MVC mapping (@Controller). Constructor injection is preferred because dependencies are explicit, immutable, and easier to unit test without Spring’s test context. @Bean methods in @Configuration classes register third-party objects you cannot annotate directly.

Follow-up: describe how the application context refreshes at startup, and what happens if two @Bean methods return the same type without @Primary—ambiguous injection failures.

REST APIs and validation

Expect to sketch a controller method with @GetMapping, @PostMapping, DTO validation via @Valid and Jakarta Bean Validation (@NotNull, @Size), and consistent error responses using @ControllerAdvice.

Discuss content negotiation (produces, consumes), status codes (201 with Location header on create), and idempotency for PUT versus PATCH.

Sample talking point: Validation errors should return 400 with field-level messages, not a generic 500. Spring’s MethodArgumentNotValidException handler keeps clients and frontend forms usable.

Data access: JPA, transactions, and pitfalls

Spring Data JPA repositories reduce boilerplate, but interviews probe lazy loading, N+1 queries, and transaction boundaries.

Questions you should handle

  • What @Transactional guarantees and where it must sit (service layer, public methods)
  • Difference between Propagation.REQUIRED and REQUIRES_NEW
  • Why calling @Transactional methods from the same class bypasses the proxy

Explain that self-invocation skips AOP proxies unless you refactor to another bean or use aspect weaving. Mention @EntityGraph or fetch joins to tame N+1 issues, and when native queries beat derived query methods.

Connection pool sizing (HikariCP defaults) and @Modifying queries for bulk updates appear in mid-level loops.

Security basics

Even if the role is not security-focused, expect Spring Security overview questions:

  • Filter chain versus method security (@PreAuthorize)
  • Difference between authentication and authorization
  • Where JWT validation fits (resource server configuration)

Describe disabling default user password in production, storing secrets outside git, and restricting actuator endpoints with separate management ports or Spring Security rules.

Testing Spring Boot applications

Layers of tests matter:

  • @WebMvcTest slices MVC and mocks services
  • @DataJpaTest hits an in-memory database for repositories
  • @SpringBootTest loads full context—slower, used sparingly

Mention Testcontainers for integration tests against real PostgreSQL or Kafka. Interviewers like hearing that unit tests should not require Boot unless testing configuration itself.

Actuator, metrics, and production readiness

spring-boot-starter-actuator exposes health, metrics, and env endpoints. Know which endpoints are sensitive (/env, /heapdump) and how to expose health on Kubernetes liveness probes without leaking internals.

Connect Micrometer to Prometheus or your observability stack. Discuss structured logging (JSON logs) and correlation IDs propagated through MDC.

Common scenario questions

Slow startup
Large classpath scanning, excessive @Bean creation, or Flyway migrations on boot. Use lazy initialization cautiously; profile autoconfiguration exclusions when needed.

Duplicate bean definitions
Two @Configuration classes defining the same bean type—resolve with @Primary, @Qualifier, or consolidate configuration.

Handling failures in @Async methods
Exceptions may not propagate to the caller; use AsyncUncaughtExceptionHandler or return CompletableFuture with explicit error handling.

Version upgrades
Spring Boot 3.x on Jakarta EE namespace (jakarta.* imports). Mention compatibility with Java 17+ and native image experiments if relevant.

Behavioral follow-ups

Interviewers often pair technical questions with design prompts:

  • Design a REST API for orders with idempotent payment callbacks
  • Add rate limiting without rewriting controllers (filter or gateway)
  • Migrate a monolithic WAR deployment to containerized Boot services

Answer with incremental steps: extract bounded contexts, introduce API gateway auth, use externalized config, add contract tests.

FAQ

Do I need to memorize every starter?
Know the major ones: web, data-jpa, security, actuator, validation. Look up niche starters when implementing.

Is WebFlux required knowledge?
For many roles, MVC suffices. Mention reactive stack if the job posting cites high-concurrency streaming or WebClient integrations.

How deep should JPA go?
Understand entity relationships, fetch types, transactions, and performance basics. Advanced tuning (second-level cache) is a plus, not always required.

What Java version should I mention?
Spring Boot 3.x targets Java 17+. LTS versions are the safe default for new services.

How do I show real experience?
Reference concrete problems: fixed N+1 query with fetch join, secured actuator, wrote Testcontainers integration test for messaging.

Configuration and profiles in depth

Spring Boot’s relaxed binding maps server.port, SERVER_PORT, and server-port consistently. Interviewers may ask how @ConfigurationProperties differs from @Value: typed immutable configuration beans with validation beat scattered string injection.

Profiles activate beans for dev, staging, and prod. @Profile("prod") guards mock payment gateways. spring.profiles.active can be set via environment variables in Kubernetes manifests. Mention spring.config.import for pulling secrets from Vault or AWS Parameter Store without baking credentials into images.

Conditional beans (@ConditionalOnProperty) keep optional integrations off the classpath until enabled—useful for feature flags in multi-tenant SaaS.

Messaging, scheduling, and background work

@EnableScheduling runs cron tasks in-process—fine for single-instance apps, dangerous when you scale horizontally without distributed locks. Prefer external schedulers or Quartz with JDBC job stores when exactly-once matters.

Spring Kafka and RabbitMQ templates appear in integration-heavy roles. Be ready to describe idempotent consumers, dead-letter queues, and how @RetryableTopic patterns reduce poison messages stalling partitions.

Observability beyond actuator

Distributed tracing with Micrometer Tracing (Brave or OpenTelemetry bridges) helps debug latency across services. Propagate trace IDs into log MDC fields so grep across pods correlates with user reports.

Custom metrics (Counter, Timer) around business events (orders placed, payments failed) beat generic JVM heap graphs in incident reviews.

API documentation and contract testing

Springdoc OpenAPI generates Swagger UI from controllers. Mention keeping DTO schemas stable for mobile clients and publishing breaking-change notices.

Consumer-driven contract tests (Spring Cloud Contract) protect microservice ecosystems when teams deploy independently.

JVM and memory talking points

Understand heap versus metaspace, why -Xmx alone is insufficient tuning, and how G1GC behaves under allocation spikes. You do not need GC expert depth, but blaming “Spring is slow” without profiling with async-profiler or JDK Flight Recorder signals junior level.

Native images with GraalVM reduce cold start for serverless Spring—note trade-offs: longer build times, reflection configuration, and not every library supports native yet.

Closing preparation tips

Block two hours to whiteboard a small REST service: entities, repository, service with @Transactional, controller, and one @WebMvcTest. Say your assumptions aloud during interviews—reviewers care about communication as much as syntax.

If you lack production Spring experience, contribute a small open-source fix or build a demo with Flyway migrations, Testcontainers, and GitHub Actions. Stories beat listing annotations from flashcards.