Spring Boot & Spring Framework Interview Cheat Sheet
Basic Level
Q: What is the Spring Framework?
A: A Java framework providing features like dependency injection, AOP, and MVC.
Q: What is Spring Boot?
A: A tool built on top of Spring that simplifies app development with auto-configuration and embedded servers.
Q: Difference between Spring and Spring Boot?
A: Spring needs manual setup, Boot provides auto-config and faster development.
Q: What is Dependency Injection in Spring?
A: A pattern where Spring injects objects into a class instead of creating them internally.
Q: What are Spring Boot Starter Dependencies?
A: Predefined dependencies to simplify configuration, e.g., spring-boot-starter-web.
Q: What is @SpringBootApplication?
A: Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan.
Q: How do you create a REST API in Spring Boot?
A: Using @RestController and mapping annotations like @GetMapping.
Q: How does Spring Boot work internally?
A: It uses [Link](), applies auto-config, and starts an embedded server.
Intermediate Level
Q: What is @Autowired?
A: Used to inject Spring beans automatically into dependent components.
Q: Difference between @Component, @Service, @Repository, and @Controller?
A: All are beans. Each represents a specific layer: generic, service, DAO, and web controller respectively.
Q: How does Spring Boot handle application properties?
A: Using [Link] or .yml and annotations like @Value or @ConfigurationProperties.
Q: What is Spring Boot DevTools?
A: Tool for hot-reloading and quick feedback during development.
Q: How to configure different environments?
A: Using profiles like [Link] and [Link].
Q: What is a Bean in Spring?
A: An object managed by the Spring container.
Q: How is a Spring Boot application deployed?
A: Via an executable JAR with an embedded server or a WAR to an external server.
Advanced Level
Q: What is Auto-Configuration?
A: Spring Boot configures beans automatically based on classpath and properties.
Q: What is CommandLineRunner?
A: An interface for running logic after the Spring context is initialized.
Spring Boot & Spring Framework Interview Cheat Sheet
Q: Difference between @ComponentScan and @Bean?
A: @ComponentScan detects components; @Bean defines manual beans.
Q: How does Spring Boot connect to a database?
A: Using starter dependencies and config in [Link].
Q: What is Spring Data JPA?
A: Simplifies database access using repositories and JPA/Hibernate.
Q: Difference between CrudRepository and JpaRepository?
A: JpaRepository adds more JPA features like pagination over CrudRepository.
Q: What is @Transactional?
A: Defines a method as transactional, rolling back on exceptions.
Q: What is Spring Security?
A: A framework for securing applications with authentication and authorization.
Q: How to secure REST APIs in Spring Boot?
A: Using Spring Security with JWT, Basic Auth, or OAuth2.
Q: What is DispatcherServlet?
A: Front controller in Spring MVC that routes requests to appropriate controllers.
Q: What is @Entity and @Id?
A: @Entity marks a JPA entity, @Id defines the primary key.
Q: Lazy vs Eager loading?
A: Lazy loads when accessed, eager loads immediately with parent.
Q: Global Exception Handling?
A: Use @ControllerAdvice with @ExceptionHandler methods.
Q: Performance optimizations?
A: Use caching, connection pools, pagination, and SQL profiling.