PrepPilotPractise free

Spring & Spring Boot interview questions

IoC, Boot auto-config, REST, data access, transactions, security

17 questions · @Bean · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is Inversion of Control and how does Spring implement it?

Inversion of Control means the framework, not the application code, controls object creation and wiring. Spring implements this using Dependency Injection, where beans and their dependencies are managed by the IoC container.

What are the main bean scopes in Spring?

The main bean scopes are singleton (one instance per container), prototype (a new instance every time it's requested), request (one per HTTP request), and session (one per HTTP session). Singleton is the default.

How do you define a REST endpoint in Spring Boot?

I use @RestController on the class and map endpoints with @RequestMapping, @GetMapping, @PostMapping, etc. Methods return objects, which are automatically serialized to JSON.

What is a Spring Boot starter?

A starter is a dependency that bundles related libraries for a specific feature, like spring-boot-starter-web for web apps. It simplifies dependency management.

Intermediate questions

How does Spring Boot auto-configuration work?

Spring Boot auto-configuration inspects the classpath and application properties to automatically configure beans for common use cases. It uses @Conditional annotations to activate configurations only when needed, reducing manual setup.

How do you externalize configuration in Spring Boot?

I use application.properties or application.yml files, and can override settings with environment variables or command-line arguments. For different environments, I use profile-specific files like application-dev.properties.

How do you validate request data in a Spring REST API?

I annotate the DTO fields with validation annotations like @NotNull, and add @Valid to the controller method parameter. Spring automatically validates and throws an exception if validation fails.

What is the N+1 problem in JPA and how do you avoid it?

The N+1 problem happens when fetching a list of entities causes additional queries for each related entity due to lazy loading. I avoid it by using fetch joins in JPQL or @EntityGraph to load associations eagerly when needed.

Explain the difference between constructor and field injection.

Constructor injection passes dependencies via the constructor, making them explicit and supporting immutability. Field injection uses @Autowired on fields, which is less visible and harder to test, so I prefer constructor injection.

How does Spring Security filter chain work?

Spring Security sets up a chain of filters that process each request, handling authentication, authorization, and other security concerns. Each filter can allow, modify, or block the request based on security rules.

How do you test a Spring MVC controller?

I use @WebMvcTest to load only the web layer and MockMvc to simulate HTTP requests. This allows fast, focused tests of controller logic without starting the full application.

What does @Transactional do and what is propagation?

@Transactional marks a method or class as transactional. Propagation defines how transactions behave when a transactional method calls another transactional method, for example, joining an existing transaction or starting a new one.

Senior questions

Describe a scenario where self-invocation breaks @Transactional. How do you solve it?

See the answer in the app, free

How would you secure a REST API with JWT using Spring Security?

See the answer in the app, free

How do you monitor a Spring Boot application in production?

See the answer in the app, free

How do you use Testcontainers in Spring Boot integration tests?

See the answer in the app, free

How do you handle exception mapping and error responses in a REST API?

See the answer in the app, free

More Java topics