Top 100 Spring Boot Interview Questions and Answers
Q1: What is Spring Boot? basics
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
Spring Boot provides auto-configuration, embedded servers, starter dependencies, production-ready features, and minimal boilerplate code.
Q3: What is auto-configuration? core
Auto-configuration automatically configures Spring application based on classpath dependencies using @EnableAutoConfiguration or @SpringBootApplication.
Q4: What is @SpringBootApplication? core
@SpringBootApplication combines @Configuration, @EnableAutoConfiguration, and @ComponentScan into a single convenient annotation.
Q5: What are starter dependencies? dependencies
Starter dependencies simplify Maven/Gradle configuration by grouping related transitive dependencies into single dependency entries.
Q6: What is application.properties file? config
application.properties provides externalized configuration for Spring Boot applications using key-value pairs.
Q7: What is application.yml file? config
application.yml is YAML alternative to application.properties with hierarchical property format.
Q8: What is embedded server in Spring Boot? server
Spring Boot includes embedded Tomcat, Jetty, or Undertow eliminating need to deploy WAR files on external servers.
Q9: What is Spring Boot Actuator? monitoring
Actuator provides production-ready endpoints for monitoring and managing applications (/health, /metrics, /env, etc).
Q10: What is /actuator/health endpoint? monitoring
/actuator/health endpoint provides application health status and detailed component health information.
Q11: What is /actuator/metrics endpoint? monitoring
/actuator/metrics endpoint exposes application metrics like JVM, CPU, memory, and custom metrics.
Q12: What is logging in Spring Boot? logging
Spring Boot uses SLF4J abstraction with Logback as default, configurable via application.properties or logback-spring.xml.
Q13: What is @Controller annotation? mvc
@Controller marks class as Spring MVC controller for handling web requests and returning views.
Q14: What is @RestController annotation? mvc
@RestController combines @Controller and @ResponseBody to build RESTful web services returning JSON/XML.
Q15: What is @RequestMapping annotation? mvc
@RequestMapping maps HTTP requests to handler methods based on URL path and HTTP method.
Q16: What is @GetMapping annotation? mvc
@GetMapping is shorthand for @RequestMapping(method = RequestMethod.GET) for handling GET requests.
Q17: What is @PostMapping annotation? mvc
@PostMapping handles POST requests with request body typically for creating resources.
Q18: What is @PathVariable annotation? mvc
@PathVariable binds URL path variable to method parameters (e.g., /users/{id}).
Q19: What is @RequestParam annotation? mvc
@RequestParam binds query parameters to method parameters (e.g., ?page=1&size=10).
Q20: What is @RequestBody annotation? mvc
@RequestBody binds HTTP request body to method parameter and deserializes JSON/XML to object.
Q21: What is @ResponseBody annotation? mvc
@ResponseBody serializes return object to JSON/XML and writes to HTTP response body.
Q22: What is @ExceptionHandler? errors
@ExceptionHandler handles specific exceptions thrown by handler methods with custom error responses.
Q23: What is @ControllerAdvice? errors
@ControllerAdvice provides global exception handling across all controllers and applies to all endpoints.
Q24: What is ResponseEntity? mvc
ResponseEntity allows full control over HTTP response including status code, headers, and body.
Q25: What is HttpStatus enum? mvc
HttpStatus provides enumerated HTTP status codes (OK, CREATED, BAD_REQUEST, NOT_FOUND, etc).
Q26: What is @Service annotation? layers
@Service marks class as service component containing business logic and transaction management.
Q27: What is @Repository annotation? layers
@Repository marks class as data access component and enables exception translation for persistence.
Q28: What is @Component annotation? core
@Component marks class as Spring component for dependency injection and bean management.
Q29: What is dependency injection? core
Dependency injection automatically provides required dependencies to classes instead of manual instantiation.
Q30: What is @Autowired annotation? core
@Autowired provides automatic dependency injection by type, matching beans with required dependencies.
Q31: What is constructor injection? core
Constructor injection passes dependencies via constructor parameters, recommended for immutability.
Q32: What is setter injection? core
Setter injection passes dependencies via setter methods for optional dependencies.
Q33: What is field injection? core
Field injection uses @Autowired on fields; convenient but less testable than constructor injection.
Q34: What is Spring Data JPA? data
Spring Data JPA reduces boilerplate for database operations with generated query methods.
Q35: What is CrudRepository? data
CrudRepository provides CRUD operations (Create, Read, Update, Delete) for entities.
Q36: What is JpaRepository? data
JpaRepository extends CrudRepository with batch operations, pagination, and sorting.
Q37: What is @Entity annotation? jpa
@Entity marks class as JPA entity mapped to database table.
Q38: What is @Table annotation? jpa
@Table specifies table name and database schema for entity.
Q39: What is @Id annotation? jpa
@Id marks field as entity primary key.
Q40: What is @GeneratedValue? jpa
@GeneratedValue specifies primary key generation strategy (AUTO, IDENTITY, SEQUENCE, TABLE).
Q41: What is @Column annotation? jpa
@Column specifies column name, nullable, length, and other database constraints.
Q42: What is @OneToOne relationship? jpa
@OneToOne represents one-to-one relationship between entities with foreign key.
Q43: What is @OneToMany relationship? jpa
@OneToMany represents one-to-many relationship where one entity has multiple child entities.
Q44: What is @ManyToOne relationship? jpa
@ManyToOne represents many-to-one relationship where multiple entities reference single parent.
Q45: What is @ManyToMany relationship? jpa
@ManyToMany represents many-to-many relationship through join table.
Q46: What is @Transactional annotation? transactions
@Transactional manages database transactions with automatic commit/rollback and isolation levels.
Q47: What is transaction isolation level? transactions
Isolation levels control transaction visibility: READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE.
Q48: What is Spring Security? security
Spring Security provides authentication, authorization, and protection against common attacks.
Q49: What is JWT token? security
JSON Web Token contains encoded claims for stateless authentication across multiple services.
Q50: What is OAuth 2.0? security
OAuth 2.0 is authorization framework allowing users to grant third-party applications access to resources.
Q51: What is @EnableWebSecurity? security
@EnableWebSecurity enables Spring Security for the application.
Q52: What is Spring Data Query Methods? data
Query methods use naming conventions to generate queries automatically (findBy, countBy, existsBy, deleteBy).
Q53: What is @Query annotation? data
@Query allows writing custom JPQL or SQL queries for repository methods.
Q54: What is Pagination? data
Pagination divides large result sets into pages using Pageable interface for efficient data retrieval.
Q55: What is Sorting? data
Sorting orders result sets by fields using Sort object in JPA queries.
Q56: What is RestTemplate? http
RestTemplate is Spring HTTP client for consuming REST APIs with synchronous requests.
Q57: What is WebClient? http
WebClient is non-blocking HTTP client for reactive HTTP requests in Spring WebFlux.
Q58: What is Spring Cloud? microservices
Spring Cloud provides tools for building microservices including service discovery, config servers, and load balancing.
Q59: What is Service Discovery? microservices
Service discovery automatically locates services in distributed environments using Eureka or Consul.
Q60: What is API Gateway? microservices
API Gateway routes requests to microservices and handles cross-cutting concerns like authentication.
Q61: What is message queue? messaging
Message queue enables asynchronous communication between services using RabbitMQ, Kafka, or JMS.
Q62: What is Spring AMQP? messaging
Spring AMQP provides template-based approach for message sending/receiving with RabbitMQ.
Q63: What is AOP? core
AOP enables separation of cross-cutting concerns like logging, security, and transactions.
Q64: What is @Aspect annotation? aop
@Aspect marks class as aspect for weaving cross-cutting concerns into business logic.
Q65: What is @Before advice? aop
@Before executes advice before method execution.
Q66: What is @After advice? aop
@After executes advice after method execution regardless of outcome.
Q67: What is @Around advice? aop
@Around wraps method execution for complete control before and after.
Q68: What is JoinPoint? aop
JoinPoint represents method execution point in aspect advice.
Q69: What is Pointcut? aop
Pointcut is expression matching join points where aspects apply.
Q70: What is caching? performance
Caching stores frequently accessed data to reduce database queries and improve performance.
Q71: What is @Cacheable? caching
@Cacheable caches method result using key, returning cached value for same arguments.
Q72: What is @CacheEvict? caching
@CacheEvict removes cached entries after method execution.
Q73: What is @CachePut? caching
@CachePut always executes method and updates cache with result.
Q74: What is validation? validation
Validation checks input constraints using annotations (@NotNull, @NotBlank, @Email, @Size, etc).
Q75: What is @Valid annotation? validation
@Valid triggers validation on method parameters with validation annotations.
Q76: What is BindingResult? validation
BindingResult holds validation errors for form objects in controller methods.
Q77: What is ModelAndView? mvc
ModelAndView combines model data and view name for returning from controller methods.
Q78: What is Model interface? mvc
Model interface holds data passed from controller to view.
Q79: What is Thymeleaf? templating
Thymeleaf is Java template engine for server-side rendering with natural HTML templates.
Q80: What is Jackson? serialization
Jackson is JSON processor for serializing/deserializing Java objects to/from JSON.
Q81: What is @JsonProperty? serialization
@JsonProperty maps Java field names to JSON properties with custom names.
Q82: What is @JsonIgnore? serialization
@JsonIgnore excludes fields from JSON serialization/deserialization.
Q83: What is Bean scope? core
Bean scope defines lifecycle: singleton, prototype, request, session, application, websocket.
Q84: What is @Scope annotation? core
@Scope specifies bean scope controlling instance creation and lifecycle.
Q85: What is @Lazy annotation? core
@Lazy defers bean initialization until first use instead of application startup.
Q86: What is @Conditional? core
@Conditional loads beans conditionally based on specified conditions.
Q87: What is Spring Profile? config
Profile enables different configurations for dev, test, and production environments.
Q88: What is @Profile annotation? config
@Profile activates bean/configuration only for specific active profiles.
Q89: What is Spring Boot testing? testing
Spring Boot provides @SpringBootTest for integration testing with application context.
Q90: What is @MockBean? testing
@MockBean replaces real bean with mock in test context for isolated testing.
Q91: What is @WebMvcTest? testing
@WebMvcTest tests controller layer without loading full application context.
Q92: What is MockMvc? testing
MockMvc provides fluent API for testing HTTP requests/responses without server.
Q93: What is Spring Boot deployment? devops
Deploy Spring Boot as JAR or WAR on cloud platforms (AWS, Azure, GCP) or containers (Docker, Kubernetes).
Q94: What is Spring WebFlux? reactive
Spring WebFlux enables reactive, non-blocking web applications using Project Reactor.
Q95: What is Mono and Flux? reactive
Mono emits 0 or 1 element; Flux emits 0 to N elements in reactive streams.
Q96: What is subscribe() method? reactive
subscribe() triggers reactive stream execution and subscribes observers to emit values.
Q97: What is flatMap operator? reactive
flatMap transforms each element to reactive stream and flattens results.
Q98: What is map operator? reactive
map transforms each element to different value using function.
Q99: What is filter operator? reactive
filter emits only elements matching predicate.
Q100: What is Spring Boot starter-parent? config
spring-boot-starter-parent provides default configurations, dependency management, and plugin settings.