Below are crisp, interview-ready answers for the high-impact Spring Boot questions you must know for a 3+ years Java Backend Developer.
1️⃣ SPRING BOOT CORE
1. What is Spring Boot?
Spring Boot is an extension of the Spring Framework that simplifies application development by providing auto-configuration, embedded servers, and starter dependencies, allowing faster production-ready applications.
2. Spring vs Spring Boot
| Spring | Spring Boot |
|---|---|
| Manual configuration | Auto configuration |
| External server required | Embedded server |
| XML heavy | Annotation + convention based |
3. What is @SpringBootApplication?
It is a meta-annotation that combines:
@Configuration@EnableAutoConfiguration@ComponentScan
4. What is Auto-Configuration?
Spring Boot automatically configures beans based on classpath dependencies, properties, and existing beans, reducing manual configuration.
5. What are Starters?
Starters are pre-defined dependency bundles like spring-boot-starter-web that simplify dependency management.
6. What is IoC?
Inversion of Control means Spring manages object creation and dependencies, not the developer.
7. What is Dependency Injection?
DI is the process of injecting dependencies into a class instead of creating them manually.
8. Types of DI
Constructor Injection ✅ (best)
Setter Injection
Field Injection (not recommended)
9. @Component vs @Service vs @Repository
All create beans, but:
@Service→ business logic@Repository→ DAO layer (adds exception translation)@Component→ generic
10. @Bean vs @Component
@Component→ class-level, auto scanned@Bean→ method-level, manual configuration
2️⃣ REST API
11. What is REST?
REST is a way of building web services where we use HTTP methods like GET, POST, PUT, and DELETE to work with data.
12. REST vs SOAP
| REST | SOAP |
|---|---|
| Lightweight | Heavy |
| JSON/XML | XML only |
| Faster | Slower |
13. HTTP Methods
14. POST vs PUT
POST → creates new resource
PUT → updates existing resource (idempotent)
15. PUT vs PATCH
PUT → full update
PATCH → partial update
16. @RestController
Combination of @Controller + @ResponseBody. Returns JSON directly.
17. @Controller vs @RestController
@Controller→ returns view@RestController→ returns JSON
18. @RequestParam vs @PathVariable
@RequestParam→ query parameter@PathVariable→ part of URL
19. @RequestBody
Used to map JSON request body to Java object.
20. What is ResponseEntity?
ResponseEntity allows us to control response body, HTTP status, and headers.
3️⃣ EXCEPTION HANDLING
21. How do you handle exceptions?
Using:
Custom exceptions
@ExceptionHandler@ControllerAdvice
22. @ExceptionHandler
Handles exceptions inside a controller.
23. @ControllerAdvice
Handles exceptions globally for all controllers.
24. Custom Exception
Create a class extending RuntimeException.
25. Custom Error Response
Return JSON with message, status, timestamp using ResponseEntity.
4️⃣ SPRING DATA JPA
26. What is JPA?
. JPA (Java Persistence API) is a Java specification used to map Java objects to database tables and manage database operations in an object-oriented way.
Without JPA:
-
Write JDBC code
-
Manage connections manually
-
Write SQL for every operation
With JPA:
-
No boilerplate JDBC code
-
Less SQL
-
Database independent
-
Object-oriented approach
27. JPA vs Hibernate
JPA → specification
Hibernate → implementation
28. What is Spring Data JPA?
It simplifies database access by removing boilerplate code.
29. What is JpaRepository?
JpaRepository is a Spring Data JPA interface that provides built-in CRUD operations along with pagination and sorting support for JPA entities.
30. CrudRepository vs JpaRepository
JpaRepository extends CrudRepository and adds more features.
31. @Entity
Marks a class as a database table.
32. @Id & @GeneratedValue
Defines primary key and auto generation strategy.
33. Relationship Mappings
OneToOne
OneToMany
ManyToOne
ManyToMany
34. LAZY vs EAGER
LAZY → loads when needed ✅
EAGER → loads immediately
LAZY loads data on demand, EAGER loads data immediately.
35. CascadeType
CascadeType defines how operations on a parent entity are automatically propagated to its related child entities.
36. N+1 Problem
Multiple DB queries due to lazy loading.
Solution: Fetch join, EntityGraph.
N+1 = 1 parent query + N child queries
Caused by LAZY loading
Solved using:
-
Fetch Join
-
EntityGraph
-
DTO projections
37. @Query
Used for custom JPQL or native queries.
38. JPQL vs SQL
JPQL → entity based
SQL → table based
5️⃣ TRANSACTIONS
39. What is Transaction?
Group of operations executed as a single unit.
40. @Transactional
Manages commit and rollback automatically.
41. ACID
Consistency
| Property | Meaning in Simple Words |
|---|---|
| A - Atomicity | All steps happen, or none happen (all-or-nothing) |
| C - Consistency | Database moves from one valid state to another (no money disappears) |
| I - Isolation | Transactions don’t interfere with each other (two people transferring at the same time won’t mix amounts) |
| D - Durability | Once committed, changes are permanent (money stays in Bob’s account) |
42. Exception in Transaction
Unchecked exception → rollback
Checked exception → commit (default)
6️⃣ CONFIGURATION
43. application.properties
Stores application configuration.
44. Properties vs YAML
YAML is more readable and hierarchical. YAML is more readable and better for hierarchical configuration, but both work the same internally. @Value, @ConfigurationProperties
45. Spring Profiles
Used to manage environment-specific configs.
A Spring Profile allows you to use different configurations for different environments.
Examples:
-
Development
-
Testing
-
Production
Each environment can have its own configuration file.
Profile-specific files
46. dev / test / prod
Use spring.profiles.active.
7️⃣ SECURITY (BASIC)
47. Spring Security
Framework to secure applications.
48. Authentication vs Authorization
Authentication → who you are
Authorization → what you can access
49. JWT
Token-based stateless authentication.
50. Securing REST APIs
Using JWT, OAuth2, or Basic Auth.
8️⃣ ACTUATOR & LOGGING
51. Actuator
Provides health, metrics, monitoring endpoints.
52. Logging Framework
Spring Boot uses Logback by default.
53. Log Levels
9️⃣ REAL PROJECT QUESTIONS (SAY CONFIDENTLY)
54. Project Architecture
Controller → Service → Repository → DB
55. Validation
Using @Valid and Bean Validation annotations.
56. Production Issues
Checked logs, DB, API response, fixed root cause.
57. Debugging
Logs, breakpoints, Actuator, Postman.
58. Performance Improvement
Pagination, lazy loading, caching, connection pooling.