Spring Boot Interview Questions for Java Engineers: Dependency Injection, Transactions, Security, and Production
Quick Overview
Prepare for Spring Boot interviews with production-focused questions on dependency injection, auto-configuration, transaction proxies, Spring Security, testing, Actuator, and incident diagnosis.
Spring Boot interview questions for Java engineers test whether you understand what the framework does for you and where that automation stops. Strong answers connect annotations to container behavior, proxy boundaries, database guarantees, security filters, tests, and production evidence. Memorizing @Autowired, @Transactional, and @SpringBootApplication is not enough.
Prepare to trace one request through the whole service. Use PracHub's Backend Engineer interview questions to rehearse the underlying API, data, security, and failure-handling decisions. PracHub question records are practice material, not predictions of a particular employer's interview.

Spring Boot interview questions: what interviewers are testing
The best Spring Boot questions reveal whether you can reason across layers. A production-minded candidate can explain the default, name the boundary where it applies, identify a failure mode, and describe a test or signal that would verify the answer.
| Area | Baseline answer | Stronger interview signal |
|---|---|---|
| Dependency injection | The container creates and wires beans | Explains ownership, scope, lifecycle, proxies, and testability |
| Auto-configuration | Boot configures beans from the classpath | Reads conditions and knows how user configuration makes it back off |
| Transactions | @Transactional starts a transaction | Defines proxy entry, propagation, rollback, database isolation, and side effects |
| Security | A filter chain authenticates requests | Separates authentication, authorization, CSRF, CORS, and object-level checks |
| Production | Actuator exposes operational data | Designs safe exposure, useful telemetry, health semantics, and incident diagnosis |
Dependency injection and the application context
Why prefer constructor injection?
Constructor injection makes required dependencies explicit, permits immutable fields, and lets a unit test instantiate the class without starting Spring. Setter injection can fit optional or reconfigurable collaborators. Field injection hides requirements and makes plain-object testing awkward. The important point is not style; it is whether an object can exist in an invalid state and who owns each dependency.
The Spring container manages bean definitions, collaborators, scopes, and lifecycle callbacks. It does not make every managed object thread-safe. A singleton bean is shared within its container, so mutable request-specific state in instance fields can race under concurrent traffic.
What causes circular-dependency failures?
If OrderService needs PaymentService and PaymentService needs OrderService through constructors, neither object can be completed first. A lazy proxy or setter can postpone the symptom, but the better interview answer questions the design: extract a smaller policy, invert one dependency, or coordinate the workflow in a third service.
What happens after a bean is constructed?
Spring populates dependencies, runs aware callbacks and bean post-processors, invokes initialization callbacks, and may return a proxy rather than the original object. That last detail explains several interview traps. Transaction, method-security, caching, and async behavior can depend on calls crossing a proxy, so this.someAnnotatedMethod() may not behave like an external call through the bean.
Spring Boot auto-configuration without magic
@SpringBootApplication combines Boot configuration, auto-configuration, and component scanning. Auto-configuration is conditional: it reacts to classes, properties, beans, and the application type that are present. It generally backs off when you provide an applicable bean or explicitly exclude a configuration.
When Boot creates an unexpected bean, do not guess from the annotation. Read the configuration properties and the condition evaluation report, inspect which auto-configuration matched, and check package scanning. The auto-configuration reference is more reliable than memorizing defaults from an older project.
External configuration also has precedence. A good answer names the source actually used in the deployment, treats secrets separately from ordinary configuration, validates typed properties at startup, and avoids scattering environment lookups through business code.
Spring transaction interview questions
Why can @Transactional appear to do nothing?
In Spring's default proxy mode, only calls that enter through the proxy are intercepted. Self-invocation can bypass transaction advice, and initialization code should not rely on a proxy that is not ready. The official @Transactional documentation also defines defaults that candidates often miss: REQUIRED propagation, database-default isolation, and rollback for RuntimeException or Error, not every checked exception.
The narrow fix may be moving the transactional operation to another bean, changing the call boundary, or using TransactionTemplate. Do not recommend self-injection reflexively; explain why the boundary was wrong.
How do REQUIRED and REQUIRES_NEW differ?
REQUIRED joins an existing transaction or creates one. REQUIRES_NEW suspends the outer transaction and starts an independent physical transaction. That independence can be useful for a carefully designed audit record, but it also needs another database connection while the outer transaction remains open. Under concurrency, an undersized pool can block or deadlock operationally.
Does a transaction make remote calls atomic?
No. A database transaction cannot roll back an email, payment-provider request, or message already accepted by another system. Keep database transactions short, avoid waiting on slow networks while holding locks, and use patterns such as idempotency keys, transactional outbox records, and compensating workflows when effects cross systems.
Is readOnly = true a guarantee?
Treat it as a semantic declaration and possible optimization hint whose enforcement depends on the transaction manager, ORM, driver, and database. It does not replace authorization or prove that no write can occur. Verify generated SQL and database behavior in the actual stack.
Spring Security interview questions
Spring Security's Servlet support is built around filters. DelegatingFilterProxy bridges the servlet container to Spring, while FilterChainProxy selects a SecurityFilterChain. Filter order matters because authentication must establish a security context before authorization evaluates access.
Authentication or authorization?
Authentication establishes the principal; authorization decides whether that principal may perform this action on this resource. A valid JWT does not prove that the caller owns the requested invoice. Enforce object-level authorization near the resource lookup or domain operation, not only through broad URL roles.
Should a REST API disable CSRF?
Not simply because it returns JSON. CSRF risk depends on whether browsers automatically attach credentials such as cookies. A stateless bearer-token API that never relies on ambient browser credentials has a different threat model from a session-cookie application. Explain credential transport, then configure CSRF deliberately. CORS is separate: it controls which browser origins may read or send certain cross-origin requests; it is not authentication.
What should a secure filter-chain answer include?
Name the credential source, validation rules, failure response, authorization policy, session strategy, and endpoint exceptions. Store passwords through an adaptive PasswordEncoder, protect secrets and signing keys, validate issuer and audience for tokens, and test denied paths. The Spring Security architecture guide is the authoritative model for the Servlet filter chain.

Testing the boundaries instead of the annotations
Use the smallest test that proves the risk. A plain unit test fits domain logic. @WebMvcTest isolates the web layer and can verify validation, serialization, security, and error contracts. @DataJpaTest fits mappings and query behavior. @SpringBootTest proves broader wiring but is slower and can hide an unclear boundary behind a large context.
For transaction behavior, include a test that crosses the real proxy and another that checks committed database state. A test method rolled back by the test framework can conceal persistence mistakes. Use a real supported database or Testcontainers when dialect, locking, isolation, or migration behavior matters.
Production and troubleshooting questions
Spring Boot Actuator provides production-ready endpoints and integrates with Micrometer. Observability combines logs, metrics, and traces; it is not the act of exposing every endpoint. Restrict sensitive management access, avoid secrets and personal data, and distinguish liveness from readiness so an overloaded dependency does not trigger the wrong recovery action.
For a slow service, start with the symptom: latency percentile, error rate, throughput, saturation, or one dependency. Correlate request traces with HTTP client latency, connection-pool usage, database queries, JVM evidence, and recent changes. High-cardinality tags such as raw user IDs or URLs can increase cost and operational risk.
For startup failures, inspect the root cause rather than the final ApplicationContext error. Look for missing configuration, duplicate or unsatisfied beans, an unexpected active profile, failed migrations, port conflicts, and condition-report evidence. For shutdown, stop accepting new work, allow bounded in-flight completion, close pools, and make background consumers idempotent when work is retried.
A framework for strong Spring Boot answers
Use SCOPE:
- Scope: Which container, request, thread, transaction, or security context owns the behavior?
- Crossing: Does the call cross the proxy, filter, process, or database boundary required for the feature?
- Outcome: What guarantee is provided, and what is only a hint or default?
- Pressure: What changes under concurrency, failure, or slow dependencies?
- Evidence: Which test, condition report, query, metric, trace, or log would verify the claim?
Practice with PracHub questions
These verified question-bank records train transferable Spring Boot reasoning. They are not predictions of an exact interview.
| PracHub question | Spring Boot practice focus | Why it helps |
|---|---|---|
| Compare Spring and Spring Boot | Auto-configuration and framework boundaries | Replaces vague “convention over configuration” claims with concrete trade-offs |
| Design Calendar Event CRUD with Unit Tests | Controllers, validation, services, persistence, and tests | Exercises a complete request path without requiring a huge system design |
| Debug row loss after SQL joins | Data access, query semantics, and verification | Trains diagnosis below the repository abstraction |
| Design signup and login service | Authentication, sessions, password storage, and authorization | Builds the security decisions a filter-chain answer must preserve |
| Handle invalid input at system level | Validation, error contracts, rate limits, and observability | Connects controller behavior to production reliability |
A seven-day preparation plan
| Day | Focus | What to do |
|---|---|---|
| Day 1 | Container | Trace bean creation, scopes, lifecycle, and one circular dependency |
| Day 2 | Boot | Explain component scanning, conditional auto-configuration, and property precedence |
| Day 3 | Transactions | Test self-invocation, rollback rules, propagation, and one concurrency failure |
| Day 4 | Security | Draw the filter chain and test authentication, authorization, CSRF, and CORS decisions |
| Day 5 | Web and data | Build one validated endpoint with persistence and precise error responses |
| Day 6 | Production | Diagnose a slow request using metrics, traces, logs, pools, and database evidence |
| Day 7 | Mock interview | Answer five questions with SCOPE, then retest every weak claim |
Frequently asked questions
Are Spring and Spring Boot interview questions the same?
They overlap, but Spring questions often focus on the IoC container, AOP, transactions, MVC, and Security. Spring Boot questions add auto-configuration, starters, external configuration, embedded runtime behavior, testing support, Actuator, packaging, and production operations.
Do I need to memorize Spring annotations?
Know the common annotations, but explain the mechanism and boundary behind each one. An interviewer learns more from why @Transactional can be bypassed or why a singleton can race than from a long list of annotation names.
Should I prepare Spring MVC and WebFlux?
Prepare the stack named in the role. For MVC, understand servlet threads, blocking dependencies, and the security filter chain. For WebFlux, understand reactive composition, backpressure, non-blocking I/O, and reactive transaction context. Do not mix their execution models casually.
How deep should Spring Security preparation go?
For a backend role, be ready to trace authentication and authorization, configure a SecurityFilterChain, discuss sessions or tokens, reason about CSRF and CORS, protect passwords and secrets, enforce object-level access, and test both allowed and denied requests.
What is the best way to answer a production incident question?
Define the user-visible symptom and timeline, check recent changes, narrow the failing layer with metrics and traces, form one hypothesis, and seek disconfirming evidence. Name a safe mitigation and the follow-up test that prevents recurrence.
Final takeaway
Spring Boot interview questions reward boundary awareness. Explain what the container owns, which calls cross a proxy or filter, where the database guarantee ends, and how production evidence changes your decision. Practice until every annotation-level answer includes a failure mode and a verification method.
Sources and Further Reading
- Spring Framework IoC container
- Spring Framework dependencies and dependency injection
- Spring Boot auto-configuration
- Spring Boot externalized configuration
- Spring Framework transaction management
- Spring Framework
@Transactionalsemantics - Spring Security Servlet architecture
- Spring Security CSRF protection
- Spring Security CORS integration
- Spring Security password storage
- Spring Boot testing
- Spring Boot Actuator production-ready features
- Spring Boot observability
Research note: This guide was checked on September 1, 2026. Spring versions and defaults evolve, so verify the documentation for the version used by your target role.
Comments (0)