Skill Booster

Quick Reference for Interviews...

Top 100 Spring Boot Interview Questions and Answers

Prepare for your Spring Boot backend interviews with this comprehensive collection of 100 Spring Boot interview questions and answers. Master essential concepts like Spring MVC, Spring Data JPA, Spring Security, REST APIs, microservices, and dependency injection. Whether you're preparing for Java backend engineering roles or Spring Boot developer positions, this guide covers everything from basic framework setup to advanced enterprise patterns. Boost your confidence with detailed explanations and practical examples for each question.

Q1: What is Spring Boot? basics

Framework Overview

Spring Boot is an opinionated framework for building stand-alone, production-grade Spring-based applications with minimal configuration.

Q2: What are advantages of Spring Boot? basics

Framework Benefits

Spring Boot provides auto-configuration, embedded servers, starter dependencies, production-ready features, and minimal boilerplate code.

Q3: What is auto-configuration? core

Spring Boot Features

Auto-configuration automatically configures Spring application based on classpath dependencies using @EnableAutoConfiguration or @SpringBootApplication.

Q4: What is @SpringBootApplication? core

Annotation

@SpringBootApplication combines @Configuration, @EnableAutoConfiguration, and @ComponentScan into a single convenient annotation.

Q5: What are starter dependencies? dependencies

Maven/Gradle

Starter dependencies simplify Maven/Gradle configuration by grouping related transitive dependencies into single dependency entries.

Q6: What is application.properties file? config

Configuration

application.properties provides externalized configuration for Spring Boot applications using key-value pairs.

Q7: What is application.yml file? config

Configuration

application.yml is YAML alternative to application.properties with hierarchical property format.

Q8: What is embedded server in Spring Boot? server

Web Container

Spring Boot includes embedded Tomcat, Jetty, or Undertow eliminating need to deploy WAR files on external servers.

Q9: What is Spring Boot Actuator? monitoring

Production Features

Actuator provides production-ready endpoints for monitoring and managing applications (/health, /metrics, /env, etc).

Q10: What is /actuator/health endpoint? monitoring

Health Checks

/actuator/health endpoint provides application health status and detailed component health information.

Q11: What is /actuator/metrics endpoint? monitoring

Metrics

/actuator/metrics endpoint exposes application metrics like JVM, CPU, memory, and custom metrics.

Q12: What is logging in Spring Boot? logging

Log Management

Spring Boot uses SLF4J abstraction with Logback as default, configurable via application.properties or logback-spring.xml.

Q13: What is @Controller annotation? mvc

Annotation

@Controller marks class as Spring MVC controller for handling web requests and returning views.

Q14: What is @RestController annotation? mvc

Annotation

@RestController combines @Controller and @ResponseBody to build RESTful web services returning JSON/XML.

Q15: What is @RequestMapping annotation? mvc

Routing

@RequestMapping maps HTTP requests to handler methods based on URL path and HTTP method.

Q16: What is @GetMapping annotation? mvc

HTTP Methods

@GetMapping is shorthand for @RequestMapping(method = RequestMethod.GET) for handling GET requests.

Q17: What is @PostMapping annotation? mvc

HTTP Methods

@PostMapping handles POST requests with request body typically for creating resources.

Q18: What is @PathVariable annotation? mvc

Request Binding

@PathVariable binds URL path variable to method parameters (e.g., /users/{id}).

Q19: What is @RequestParam annotation? mvc

Request Binding

@RequestParam binds query parameters to method parameters (e.g., ?page=1&size=10).

Q20: What is @RequestBody annotation? mvc

Request Binding

@RequestBody binds HTTP request body to method parameter and deserializes JSON/XML to object.

Q21: What is @ResponseBody annotation? mvc

Response Binding

@ResponseBody serializes return object to JSON/XML and writes to HTTP response body.

Q22: What is @ExceptionHandler? errors

Exception Handling

@ExceptionHandler handles specific exceptions thrown by handler methods with custom error responses.

Q23: What is @ControllerAdvice? errors

Global Error Handling

@ControllerAdvice provides global exception handling across all controllers and applies to all endpoints.

Q24: What is ResponseEntity? mvc

HTTP Response

ResponseEntity allows full control over HTTP response including status code, headers, and body.

Q25: What is HttpStatus enum? mvc

HTTP Status

HttpStatus provides enumerated HTTP status codes (OK, CREATED, BAD_REQUEST, NOT_FOUND, etc).

Q26: What is @Service annotation? layers

Service Layer

@Service marks class as service component containing business logic and transaction management.

Q27: What is @Repository annotation? layers

Data Layer

@Repository marks class as data access component and enables exception translation for persistence.

Q28: What is @Component annotation? core

Component Stereotype

@Component marks class as Spring component for dependency injection and bean management.

Q29: What is dependency injection? core

Inversion of Control

Dependency injection automatically provides required dependencies to classes instead of manual instantiation.

Q30: What is @Autowired annotation? core

Dependency Injection

@Autowired provides automatic dependency injection by type, matching beans with required dependencies.

Q31: What is constructor injection? core

Dependency Injection

Constructor injection passes dependencies via constructor parameters, recommended for immutability.

Q32: What is setter injection? core

Dependency Injection

Setter injection passes dependencies via setter methods for optional dependencies.

Q33: What is field injection? core

Dependency Injection

Field injection uses @Autowired on fields; convenient but less testable than constructor injection.

Q34: What is Spring Data JPA? data

ORM Framework

Spring Data JPA reduces boilerplate for database operations with generated query methods.

Q35: What is CrudRepository? data

Data Access

CrudRepository provides CRUD operations (Create, Read, Update, Delete) for entities.

Q36: What is JpaRepository? data

Data Access

JpaRepository extends CrudRepository with batch operations, pagination, and sorting.

Q37: What is @Entity annotation? jpa

Entity Mapping

@Entity marks class as JPA entity mapped to database table.

Q38: What is @Table annotation? jpa

Entity Mapping

@Table specifies table name and database schema for entity.

Q39: What is @Id annotation? jpa

Entity Mapping

@Id marks field as entity primary key.

Q40: What is @GeneratedValue? jpa

Entity Mapping

@GeneratedValue specifies primary key generation strategy (AUTO, IDENTITY, SEQUENCE, TABLE).

Q41: What is @Column annotation? jpa

Entity Mapping

@Column specifies column name, nullable, length, and other database constraints.

Q42: What is @OneToOne relationship? jpa

Entity Relationships

@OneToOne represents one-to-one relationship between entities with foreign key.

Q43: What is @OneToMany relationship? jpa

Entity Relationships

@OneToMany represents one-to-many relationship where one entity has multiple child entities.

Q44: What is @ManyToOne relationship? jpa

Entity Relationships

@ManyToOne represents many-to-one relationship where multiple entities reference single parent.

Q45: What is @ManyToMany relationship? jpa

Entity Relationships

@ManyToMany represents many-to-many relationship through join table.

Q46: What is @Transactional annotation? transactions

Transaction Management

@Transactional manages database transactions with automatic commit/rollback and isolation levels.

Q47: What is transaction isolation level? transactions

Database Transactions

Isolation levels control transaction visibility: READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE.

Q48: What is Spring Security? security

Authentication

Spring Security provides authentication, authorization, and protection against common attacks.

Q49: What is JWT token? security

Authentication

JSON Web Token contains encoded claims for stateless authentication across multiple services.

Q50: What is OAuth 2.0? security

Authorization

OAuth 2.0 is authorization framework allowing users to grant third-party applications access to resources.

Q51: What is @EnableWebSecurity? security

Security Configuration

@EnableWebSecurity enables Spring Security for the application.

Q52: What is Spring Data Query Methods? data

Data Access

Query methods use naming conventions to generate queries automatically (findBy, countBy, existsBy, deleteBy).

Q53: What is @Query annotation? data

Custom Queries

@Query allows writing custom JPQL or SQL queries for repository methods.

Q54: What is Pagination? data

Data Retrieval

Pagination divides large result sets into pages using Pageable interface for efficient data retrieval.

Q55: What is Sorting? data

Data Retrieval

Sorting orders result sets by fields using Sort object in JPA queries.

Q56: What is RestTemplate? http

HTTP Client

RestTemplate is Spring HTTP client for consuming REST APIs with synchronous requests.

Q57: What is WebClient? http

Async HTTP Client

WebClient is non-blocking HTTP client for reactive HTTP requests in Spring WebFlux.

Q58: What is Spring Cloud? microservices

Distributed Systems

Spring Cloud provides tools for building microservices including service discovery, config servers, and load balancing.

Q59: What is Service Discovery? microservices

Microservices

Service discovery automatically locates services in distributed environments using Eureka or Consul.

Q60: What is API Gateway? microservices

Microservices

API Gateway routes requests to microservices and handles cross-cutting concerns like authentication.

Q61: What is message queue? messaging

Asynchronous Communication

Message queue enables asynchronous communication between services using RabbitMQ, Kafka, or JMS.

Q62: What is Spring AMQP? messaging

Message Broker

Spring AMQP provides template-based approach for message sending/receiving with RabbitMQ.

Q63: What is AOP? core

Aspect-Oriented Programming

AOP enables separation of cross-cutting concerns like logging, security, and transactions.

Q64: What is @Aspect annotation? aop

Aspect Annotation

@Aspect marks class as aspect for weaving cross-cutting concerns into business logic.

Q65: What is @Before advice? aop

Aspect Advice

@Before executes advice before method execution.

Q66: What is @After advice? aop

Aspect Advice

@After executes advice after method execution regardless of outcome.

Q67: What is @Around advice? aop

Aspect Advice

@Around wraps method execution for complete control before and after.

Q68: What is JoinPoint? aop

Aspect Concepts

JoinPoint represents method execution point in aspect advice.

Q69: What is Pointcut? aop

Aspect Concepts

Pointcut is expression matching join points where aspects apply.

Q70: What is caching? performance

Performance Optimization

Caching stores frequently accessed data to reduce database queries and improve performance.

Q71: What is @Cacheable? caching

Cache Annotation

@Cacheable caches method result using key, returning cached value for same arguments.

Q72: What is @CacheEvict? caching

Cache Annotation

@CacheEvict removes cached entries after method execution.

Q73: What is @CachePut? caching

Cache Annotation

@CachePut always executes method and updates cache with result.

Q74: What is validation? validation

Input Validation

Validation checks input constraints using annotations (@NotNull, @NotBlank, @Email, @Size, etc).

Q75: What is @Valid annotation? validation

Bean Validation

@Valid triggers validation on method parameters with validation annotations.

Q76: What is BindingResult? validation

Validation Results

BindingResult holds validation errors for form objects in controller methods.

Q77: What is ModelAndView? mvc

MVC Response

ModelAndView combines model data and view name for returning from controller methods.

Q78: What is Model interface? mvc

MVC Model

Model interface holds data passed from controller to view.

Q79: What is Thymeleaf? templating

Template Engine

Thymeleaf is Java template engine for server-side rendering with natural HTML templates.

Q80: What is Jackson? serialization

JSON Library

Jackson is JSON processor for serializing/deserializing Java objects to/from JSON.

Q81: What is @JsonProperty? serialization

JSON Annotation

@JsonProperty maps Java field names to JSON properties with custom names.

Q82: What is @JsonIgnore? serialization

JSON Annotation

@JsonIgnore excludes fields from JSON serialization/deserialization.

Q83: What is Bean scope? core

Spring Beans

Bean scope defines lifecycle: singleton, prototype, request, session, application, websocket.

Q84: What is @Scope annotation? core

Spring Beans

@Scope specifies bean scope controlling instance creation and lifecycle.

Q85: What is @Lazy annotation? core

Spring Beans

@Lazy defers bean initialization until first use instead of application startup.

Q86: What is @Conditional? core

Conditional Beans

@Conditional loads beans conditionally based on specified conditions.

Q87: What is Spring Profile? config

Environment Configuration

Profile enables different configurations for dev, test, and production environments.

Q88: What is @Profile annotation? config

Active Profile

@Profile activates bean/configuration only for specific active profiles.

Q89: What is Spring Boot testing? testing

Test Framework

Spring Boot provides @SpringBootTest for integration testing with application context.

Q90: What is @MockBean? testing

Mocking in Tests

@MockBean replaces real bean with mock in test context for isolated testing.

Q91: What is @WebMvcTest? testing

MVC Testing

@WebMvcTest tests controller layer without loading full application context.

Q92: What is MockMvc? testing

HTTP Testing

MockMvc provides fluent API for testing HTTP requests/responses without server.

Q93: What is Spring Boot deployment? devops

Production Deployment

Deploy Spring Boot as JAR or WAR on cloud platforms (AWS, Azure, GCP) or containers (Docker, Kubernetes).

Q94: What is Spring WebFlux? reactive

Reactive Framework

Spring WebFlux enables reactive, non-blocking web applications using Project Reactor.

Q95: What is Mono and Flux? reactive

Reactive Types

Mono emits 0 or 1 element; Flux emits 0 to N elements in reactive streams.

Q96: What is subscribe() method? reactive

Reactive Programming

subscribe() triggers reactive stream execution and subscribes observers to emit values.

Q97: What is flatMap operator? reactive

Reactive Operators

flatMap transforms each element to reactive stream and flattens results.

Q98: What is map operator? reactive

Reactive Operators

map transforms each element to different value using function.

Q99: What is filter operator? reactive

Reactive Operators

filter emits only elements matching predicate.

Q100: What is Spring Boot starter-parent? config

Project Setup

spring-boot-starter-parent provides default configurations, dependency management, and plugin settings.