Interview questions

Spring Framework Interview Questions: 20 Answers Interviewers Expect

July 3, 2025Updated May 28, 202619 min read
Top 30 Most Common Spring Framework Interview Questions You Should Prepare For

Spring Framework interview questions with crisp answers, the follow-up probes interviewers use, and the Spring concepts candidates most often need to explain.

Most candidates who struggle with Spring Framework interview questions already know Spring. The problem is that knowing Spring and being able to answer Spring Framework interview questions cleanly under live pressure are two completely different skills. This guide gives you the short answer first — the version that comes out in 20 seconds without stumbling — and then the follow-up probe the interviewer will use to find out whether you actually understand it or just memorized it.

The pattern matters because interviewers are not grading a written exam. They are watching whether you can hold a technical idea in your head, express it simply, and then go deeper when pushed. That sequence — short answer, then earned depth — is what separates candidates who sound prepared from candidates who sound like they read a documentation page the night before.

Start with the one-sentence answer, then earn the second sentence

The instinct before a technical interview is to memorize more. More terms, more acronyms, more framework internals. That instinct is usually wrong. The candidates who land offers are the ones who can say the right thing in 20 seconds, then back it up with a real example when the interviewer follows up. Everything in this guide is structured that way: short answer first, follow-up second.

What is Spring Framework, in plain interview language?

The short answer: Spring is an application framework for Java that manages object creation, wiring, and lifecycle so you can focus on writing business logic instead of plumbing.

That sentence is enough to open the door. The follow-up the interviewer will use is almost always a variation of: "Can you give me an example of what that means in a real application?" This is where most candidates stumble — they go back to the definition instead of showing the framework in motion. The right move is to describe a service layer: you have a `UserService` that depends on a `UserRepository`. Without Spring, you instantiate both manually and wire them together in every class that needs them. With Spring, you declare the dependency, and the container provides it. That is the core value proposition, and it is much more convincing than listing modules.

The Spring Framework reference documentation describes it as a "comprehensive programming and configuration model" — which is accurate but not what you want to say out loud in an interview. Translate it.

Why do interviewers care more about clarity than jargon?

A hiring manager who has interviewed 50 Java candidates has heard the phrase "inversion of control container" approximately 50 times. What they have heard far less often is a candidate who can describe what actually happens when a Spring application starts up and a bean gets created without using a single piece of Spring vocabulary.

The test is not whether you know the words. It is whether you can describe the moving parts without them. If you can explain that Spring reads your class definitions, figures out what each one needs, creates them in the right order, and hands them to each other — you have demonstrated understanding. If you can only say "IoC and DI via the container," you have demonstrated vocabulary. Senior engineers who conduct interviews consistently say they prefer the candidate who says something slightly imprecise but clearly understood over the candidate who recites the correct term without being able to unpack it.

Get dependency injection right before you try to sound senior

Dependency injection in Spring is the concept that trips up more candidates than any other — not because it is hard, but because most people explain it at the wrong level. They define it correctly and then stop, which invites the follow-up that exposes the gap.

What is dependency injection, and why does constructor injection usually win?

The short answer: Dependency injection means Spring provides an object's dependencies rather than the object creating them itself. Constructor injection is preferred because it makes dependencies explicit, required, and testable.

The follow-up will almost always be: "Why not just use field injection with `@Autowired`?" This is where the answer needs to go one level deeper. Field injection hides dependencies — you cannot tell from the constructor signature what a class needs, which makes it harder to test. With constructor injection, you can instantiate the class in a unit test by passing mock dependencies directly, without a Spring context at all. Immutability is the other argument: constructor-injected fields can be `final`, which means the object's dependencies cannot change after construction. For a `UserService` that depends on a `UserRepository`, that guarantee matters in a concurrent application.

The Spring documentation on dependency injection explicitly recommends constructor injection for mandatory dependencies — cite that if the interviewer pushes back.

When does setter injection still make sense?

Setter injection is the right answer for optional dependencies — the ones that have a sensible default and do not need to be provided for the object to function. If a caching layer is optional and the service should work without it, setter injection is a reasonable choice. The interviewer follow-up here is: "Are you using it because the dependency is genuinely optional, or because it was easier to write?" That question is designed to find out whether the candidate made a deliberate decision or just took the path of least resistance. Have an honest answer ready.

Why do circular dependencies make people nervous in Spring?

Two services that each depend on the other — `ServiceA` needs `ServiceB`, `ServiceB` needs `ServiceA` — create a circular dependency that Spring cannot resolve with constructor injection at all. It will throw a `BeanCurrentlyInCreationException`. With field or setter injection, Spring can sometimes work around it, but the real answer the interviewer wants is not "how do you fix it" but "why does it exist." Circular dependencies are a design smell. They usually mean the two services share a concern that belongs in a third class. The interviewer is checking whether you reach for a workaround or whether you recognize the structural problem.

Know the bean story: scope, lifecycle, and the stuff interviewers poke at

The Spring bean lifecycle is one of the most reliable topics in any Java backend interview. It comes up because it touches nearly everything else — scopes, initialization hooks, post-processors, and destruction callbacks. If you can narrate the lifecycle in a spoken answer, you signal that you understand the container, not just the annotations.

How does the Spring bean lifecycle actually work?

The short answer: Spring instantiates the bean, injects its dependencies, calls any initialization callbacks, makes the bean available for use, and then calls destruction callbacks when the context closes.

The follow-up is usually: "What hooks are available during initialization?" The answer the interviewer wants includes `@PostConstruct`, implementing `InitializingBean`, or defining a custom `initMethod` in the bean definition. A concrete example that lands well: a component that opens a connection pool on startup using `@PostConstruct` and releases it on shutdown using `@PreDestroy`. That is a real pattern that shows you have used the lifecycle, not just read about it. Bean post-processors — classes that implement `BeanPostProcessor` — are the more advanced follow-up, and knowing that they run before and after initialization puts you ahead of most candidates.

What are the common bean scopes, and when would you use each one?

Singleton is the default: one instance per Spring container, shared across the application. Use it for stateless services — your `OrderService`, your `PaymentProcessor`. Prototype creates a new instance every time one is requested. Use it for stateful objects where each caller needs its own copy. Request scope creates one instance per HTTP request, which is the right choice for objects that hold request-specific data in a web application. Session scope lives for the duration of an HTTP session, which fits user-preference objects or shopping carts.

The follow-up that catches people: "What happens if a singleton bean depends on a prototype bean?" The singleton gets created once, and the prototype dependency gets injected once at that time — meaning the singleton always holds the same prototype instance, which defeats the purpose of prototype scope. The fix involves method injection or using `ObjectFactory`. Knowing that edge case exists is what makes the answer feel lived-in rather than memorized.

Why do BeanFactory and ApplicationContext both exist?

`BeanFactory` is the basic container — it can create and wire beans, and that is about it. `ApplicationContext` extends it and adds event publishing, resource loading, internationalization support, and easier integration with Spring's higher-level features. In practice, you almost always use `ApplicationContext`. The follow-up the interviewer uses is: "When would you actually use `BeanFactory` directly?" The honest answer is rarely — perhaps in a constrained environment where startup memory is critical. The point of the question is to check whether you understand that `ApplicationContext` is not just a renamed `BeanFactory`, but a meaningfully richer abstraction.

Explain Spring MVC like you've actually traced a request

Spring MVC request flow is one of the cleaner topics to answer well because it has a natural sequence. Walk the request through the system in order, and the answer almost structures itself.

How does a request move through DispatcherServlet?

The short answer: The `DispatcherServlet` receives every request, delegates to a handler mapping to find the right controller, calls the controller method, takes the return value, and passes it to a view resolver or message converter.

The follow-up is immediate: "What changes when the response is JSON instead of a rendered view?" The answer is that `@ResponseBody` or `@RestController` bypasses the view resolver entirely. Spring uses a `HttpMessageConverter` — typically `MappingJackson2HttpMessageConverter` — to serialize the return object directly to the response body. That distinction shows you understand the two different response paths in Spring MVC, which is exactly what the interviewer is probing for.

What's the difference between @RequestMapping and the methods on it?

`@RequestMapping` is the general-purpose annotation that maps a request to a handler method. The composed annotations — `@GetMapping`, `@PostMapping`, `@PutMapping`, `@DeleteMapping` — are shortcuts that include the HTTP method constraint. The interviewer follow-up is usually about request matching: "How does Spring decide which method to call when two methods share the same path?" The answer involves specificity — method, headers, params, and content type all narrow the match. The practical point is that `@GetMapping("/users/{id}")` is clearer to read and less error-prone than `@RequestMapping(value="/users/{id}", method=RequestMethod.GET)`, which is why most modern Spring code uses the composed variants.

Where does JdbcTemplate fit into Spring data access?

`JdbcTemplate` handles the boilerplate of JDBC — opening connections, executing statements, mapping results, closing resources — so you write the SQL and the row mapper, not the plumbing. The follow-up is: "Why would you use `JdbcTemplate` instead of Spring Data JPA?" The honest answer is that for simple, performance-sensitive queries where you want full control over the SQL, `JdbcTemplate` is less opaque than JPA. Teams that need complex reporting queries or want to avoid the N+1 problem often keep `JdbcTemplate` alongside their JPA repositories rather than replacing one with the other. That nuance — knowing both tools have a place — is what a senior answer sounds like.

Spring Boot is the shortcut, but interviewers still want to know how it works

Spring Boot interview questions are common at every level because Boot is now the default starting point for new Spring applications. The risk is that candidates who have only ever used Boot cannot explain what it is actually doing — and interviewers probe for exactly that.

What is Spring Boot auto-configuration solving in practice?

Before Boot, wiring a Spring application meant writing XML or Java configuration for every component: the data source, the transaction manager, the MVC dispatcher, the message converters. Auto-configuration reads the classpath and applies sensible defaults automatically. If `spring-boot-starter-data-jpa` is on the classpath and a `DataSource` bean is not explicitly defined, Boot configures one using the properties in `application.properties`. The follow-up: "How does auto-configuration know what to apply?" The answer is `@ConditionalOn*` annotations — `@ConditionalOnClass`, `@ConditionalOnMissingBean` — that make each configuration class apply only when the right conditions are met. Knowing that mechanism shows you understand Boot as a system, not just a project template.

How do you explain starters without sounding memorized?

A starter is a curated set of dependencies packaged together for a specific purpose. `spring-boot-starter-web` pulls in Spring MVC, an embedded Tomcat, Jackson, and validation libraries — everything a web application needs, at compatible versions. The interviewer follow-up: "What is the risk of relying on starters without understanding what they include?" The answer is classpath surprises — a starter might bring in a library version that conflicts with something else, or include a component you do not need. Starters reduce friction; they do not replace knowing what is actually in your dependency tree.

What changes when Spring Boot meets Spring Framework 6 and Jakarta?

Spring Framework 6 and Spring Boot 3 migrated from the `javax.` namespace to `jakarta.` as part of the move to Jakarta EE 9+. Every import that previously used `javax.servlet`, `javax.persistence`, or `javax.validation` now uses `jakarta.servlet`, `jakarta.persistence`, and `jakarta.validation`. The Spring Boot 3 migration guide covers this in detail. The interviewer follow-up is practical: "What breaks first when you upgrade?" The answer is usually third-party libraries that still use the `javax` namespace — they become incompatible until they release their own Jakarta-compatible versions. Knowing that the namespace change is a dependency coordination problem, not just a find-and-replace exercise, is the senior-level answer.

Use AOP terms without turning the answer into a glossary

Spring AOP concepts are a vocabulary test that most candidates pass and a comprehension test that fewer do. The goal is to define the terms quickly and then immediately show them in a real context.

What are join point, advice, pointcut, and aspect?

The short answer: A join point is a point in execution where advice can be applied — typically a method call. Advice is the code that runs at that point. A pointcut is the expression that selects which join points to apply advice to. An aspect combines a pointcut with advice into a reusable module.

The follow-up is always: "Give me an example." The canonical one is logging: an aspect with a pointcut that matches all methods in the service layer, and advice that logs the method name and execution time before and after the call. That example proves the terms are not just vocabulary — they map to something real.

How does Spring AOP use proxies?

Spring AOP works by wrapping the target bean in a proxy. When another bean calls a method on the target, it actually calls the proxy, which applies the advice and then delegates to the real method. The follow-up: "When does Spring use JDK dynamic proxies versus CGLIB?" JDK proxies require the target to implement an interface — the proxy implements the same interface. CGLIB creates a subclass of the target class, which means it works even without an interface. Spring Boot defaults to CGLIB for most cases. The practical implication: if a class is `final`, CGLIB cannot subclass it, and the proxy will fail.

Why do transactions usually show up in Spring AOP questions?

`@Transactional` is implemented as AOP advice. The transaction proxy wraps the method call, starts a transaction before the method runs, and commits or rolls back after it returns. The follow-up that catches people: "What happens if you call a `@Transactional` method from another method in the same class?" The proxy is bypassed — the call goes directly to the object, not through the proxy, so the transaction advice never fires. This self-invocation problem is a real production bug that has surprised many teams, and knowing about it signals that you have used `@Transactional` in anger, not just read the documentation.

Answer the follow-ups that separate "studied it" from "used it"

The last category of Spring testing strategy questions is where the interview usually gets interesting. These are the questions that do not have a single right answer — they have a right shape of answer, and the interviewer is watching how you reason through them.

What happens when a bean is lazy-initialized?

Lazy initialization means the bean is not created when the application context starts — it is created the first time something requests it. The startup benefit is real: fewer beans created upfront means faster startup, which matters in serverless or short-lived container environments. The risk is that configuration errors surface at request time rather than at startup. If a lazy bean has a misconfigured dependency, the application will start cleanly and then fail in production when the first request triggers initialization. The follow-up: "When would you use lazy initialization deliberately?" The answer is beans that are expensive to create and rarely used — a batch processor that runs once a day does not need to be created on every application startup.

How do @SpringBootTest, @MockBean, and slice tests differ?

`@SpringBootTest` loads the full application context — it is the closest thing to running the real application, which makes it accurate and slow. `@MockBean` replaces a bean in the context with a Mockito mock, useful when you want a real context but need to isolate one dependency. Slice tests — `@WebMvcTest`, `@DataJpaTest`, `@JsonTest` — load only the slice of the context relevant to the layer under test. `@WebMvcTest` loads the MVC layer without the service or persistence layer, which makes controller tests fast and focused. The follow-up: "What is the risk of using `@SpringBootTest` for everything?" Slow test suites that developers stop running, which defeats the purpose of having tests.

What is a FactoryBean, and why does it confuse people?

A `FactoryBean` is a Spring bean whose job is to produce another object. When Spring encounters a `FactoryBean` in the context, it calls `getObject()` to get the actual bean that gets registered. The confusion is that the `FactoryBean` itself is not the bean you use — it is the factory that creates it. The follow-up: "How do you get the `FactoryBean` instance itself rather than the object it produces?" Prefix the bean name with `&` when calling `getBean()`. That detail is the kind of thing you only know if you have actually worked with it, which is exactly why interviewers ask it.

Avoid the answers that make Spring sound like wallpaper

Spring interview questions have a failure mode that is specific to this framework: technically correct answers that are so abstract they could describe any framework, or any enterprise software system, and mean nothing.

Why do vague answers sound weak even when they're technically correct?

"Spring promotes loose coupling through inversion of control" is true. It is also something that could appear on a marketing brochure. The interviewer follow-up will be: "Can you show me what that looks like in code?" If the answer to that question is another abstraction — "well, you define your beans and Spring wires them" — the candidate has confirmed they do not have a concrete mental model. The fix is to always have a specific class, a specific dependency, and a specific problem in mind before you start the answer. The abstraction earns its place after the example, not before it.

What does a senior-level answer actually add?

A senior answer names the tradeoff, the failure mode, and the production consequence. For singleton scope: "It is the default and the right choice for stateless services, but if a singleton holds mutable state, you have a concurrency bug waiting to happen." For `@Transactional`: "It works correctly when called through the proxy, but self-invocation bypasses the proxy and the transaction never starts." One concrete caution added to a correct definition is the difference between a junior answer and a senior one. The interviewer is not looking for more information — they are looking for evidence that you have thought about what goes wrong.

What should you say when you do not know the exact detail?

State the core idea you are confident in, acknowledge the edge case, and keep the conversation moving. "I know Spring defaults to CGLIB proxies in Boot 3, and I know there are constraints around final classes — I would want to verify the exact fallback behavior before committing to that in a production decision." That answer is more credible than a confident guess, and it shows you understand the shape of the problem even if you do not have every detail memorized. Interviewers respect intellectual honesty far more than bluffing, and a good interviewer will often fill in the gap themselves — which turns the moment into a conversation rather than an interrogation.

How Verve AI Can Help You Prepare for Your Java Backend Engineer Interview

The structural problem this guide has been solving — knowing Spring but not being able to express it cleanly under live pressure — is exactly what practice is supposed to fix. The challenge is that most practice is passive: reading answers, nodding along, feeling prepared. What actually builds the skill is being asked the question cold, giving the answer out loud, and getting feedback on whether the short version landed before the follow-up came.

Verve AI Interview Copilot is built for that specific loop. It listens in real-time as you work through Spring questions out loud, responds to what you actually said — not a canned prompt — and surfaces the follow-up questions that would expose a gap in a real interview. If your answer to the bean lifecycle question skipped initialization callbacks, Verve AI Interview Copilot will probe that gap the same way a senior interviewer would. The practice is live, not scripted. Verve AI Interview Copilot stays invisible while it works, so the session feels like an interview, not a rehearsal. For Spring specifically, where the gap between knowing the concept and explaining it crisply is exactly what gets candidates filtered out, that kind of real-time feedback is the practice that actually transfers to the room.

Conclusion

The whole point of this guide is a single idea: Spring answers should start short, stay concrete, and only go deeper when the interviewer asks. The candidates who sound prepared are not the ones who memorized the most — they are the ones who practiced the 20-second version until it came out clean, and then had a real example ready for the follow-up.

Before your interview, take five of the questions from this guide and say the short answer out loud. Not to yourself silently — out loud, as if someone is listening. That is the version of the answer that has to survive. If it comes out clear and you can follow it with a specific example, you are ready. If it comes out as a list of terms, you have more practicing to do. The knowledge is usually there. The delivery is what the interview actually tests.

JM

James Miller

Career Coach

Ace your live interviews with AI support!

Get Started For Free

Available on Mac, Windows and iPhone