I work in government tech in Bhubaneswar and have spent years writing Java backend systems. When my colleagues started preparing for TCS and Infosys interviews, I noticed they were reading 50-page PDFs for answers that should take 3 sentences. So I wrote this — 30 real Spring Boot questions with short, honest answers. No padding. No theory lectures. Just what you actually need.
Table of contents
What is Spring Boot and how is it different from Spring Framework?
What is the purpose of @SpringBootApplication annotation?
What is Auto-Configuration in Spring Boot?
What is the difference between @Component, @Service, @Repository and @Controller?
What is Dependency Injection and how does Spring Boot implement it?
What is the difference between @RestController and @Controller?
What are Spring Boot Starters?
What is application.properties and what is it used for?
What is the difference between @GetMapping, @PostMapping, @PutMapping and @DeleteMapping?
How does Spring Boot connect to a database?
What is JPA and how is it used in Spring Boot?
What is a Spring Boot Repository and what is JpaRepository?
What is the difference between @PathVariable and @RequestParam?
What is Spring Security and how do you add it to Spring Boot?
What is JWT and how is it used with Spring Boot?
What is the difference between @Bean and @Component?
What is Actuator in Spring Boot?
What is the difference between @RequestBody and @ResponseBody?
What is a Microservice and how does Spring Boot support it?
What is @Transactional and when do you use it?
What is the difference between SOAP and REST?
What is Spring Boot DevTools?
What is the difference between findById() and getById() in JPA?
What is Lombok and why is it used in Spring Boot projects?
What is an Exception Handler in Spring Boot?
What is the difference between PUT and PATCH?
What is Connection Pooling and does Spring Boot support it?
What is the use of @Value annotation?
What is the difference between Spring Boot and Spring MVC?
What is an Embedded Server in Spring Boot?
1. What is Spring Boot and how is it different from Spring Framework?
Spring Boot is an opinionated layer on top of the Spring Framework that provides auto-configuration, starter dependencies, embedded servers, and production features so you can create runnable applications with minimal setup. Spring (the framework) provides the core IoC, AOP, data, and ecosystem; Spring Boot makes it easy to get a Spring application up and running quickly.
Example (main class):
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
2. What is the purpose of @SpringBootApplication annotation?
@SpringBootApplication is a convenience meta-annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. Put it on your main class to enable auto-configuration, component scanning in the package and subpackages, and to declare configuration.
Example:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
3. What is Auto-Configuration in Spring Boot?
Auto-configuration attempts to automatically configure your Spring application based on the dependencies present on the classpath and sensible defaults. You can override auto-configuration by defining your own beans or by excluding specific auto-configuration classes.
Example: Let Spring Boot create a DataSource when spring-boot-starter-data-jpa and DB driver are on the classpath; override by providing your own DataSource bean:
@Bean
public DataSource myDataSource() {
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl("jdbc:postgresql://localhost:5432/demo");
ds.setUsername("user");
ds.setPassword("pass");
return ds;
}
You can also exclude:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class MyApplication { ... }
4. What is the difference between @Component, @Service, @Repository and @Controller?
All four are specializations of @Component and tell Spring to manage that class as a bean. @Service marks business logic classes, @Repository marks database access classes and adds exception translation, and @Controller marks web layer classes that handle HTTP requests. Using the right annotation makes your code readable and allows Spring to apply specific behaviour to each layer.
5. What is Dependency Injection and how does Spring Boot implement it?
Dependency Injection means that instead of a class creating its own dependencies, Spring creates and injects them. This makes your code loosely coupled and easier to test. Spring Boot supports three types — constructor injection (recommended), setter injection, and field injection via @Autowired.
Example:
@Service
public class UserService {
private final UserRepository userRepository;
// Constructor injection — recommended public UserService(UserRepository userRepository) { this.userRepository = userRepository; }
}
6. What is the difference between @RestController and @Controller?
@Controller is used for traditional MVC applications where you return a view (like a JSP page). @RestController combines @Controller and @ResponseBody — it automatically serializes the return value to JSON and writes it directly to the HTTP response. In modern REST API development, you will almost always use @RestController.
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping("/{id}")
public User getUser(@PathVariable Long id)
{
return userService.findById(id);
}
}
7. What are Spring Boot Starters?
Starters are pre-packaged dependency bundles that simplify your pom.xml. Instead of adding 10 separate dependencies for web development, you add one — spring-boot-starter-web — and Spring Boot brings everything needed. Common starters include spring-boot-starter-data-jpa, spring-boot-starter-security, and spring-boot-starter-test.
8. What is application.properties and what is it used for?
application.properties is the main configuration file in Spring Boot located in src/main/resources. You use it to configure database connections, server port, logging levels, and any custom properties your application needs. You can also use application.yml as an alternative with cleaner formatting.
Maven:
propertiesserver.port=8081 spring.datasource.url=jdbc:postgresql://localhost:5432/mydb spring.datasource.username=postgres spring.datasource.password=secret spring.jpa.hibernate.ddl-auto=update
9. What is the difference between @GetMapping, @PostMapping, @PutMapping and @DeleteMapping?
These are shortcut annotations for mapping HTTP methods to controller methods. @GetMapping handles GET requests for fetching data, @PostMapping handles POST for creating data, @PutMapping handles PUT for updating, and @DeleteMapping handles DELETE for removing data. They make your REST API code cleaner and more readable than using @RequestMapping with a method parameter.
10. How does Spring Boot connect to a database?
Spring Boot connects to a database using the configuration in application.properties. You add the database dependency (like spring-boot-starter-data-jpa), add your database driver (like PostgreSQL or MySQL), and configure the datasource URL, username, and password. Spring Boot auto-configures Hibernate as the JPA provider automatically.
@Entity
@Table(name = "users")
public class User {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
// getters and setters
}
Change server port:
server.port=9090
11. What is JPA and how is it used in Spring Boot?
JPA stands for Java Persistence API — it is a specification for mapping Java objects to database tables. Spring Boot uses Hibernate as the default JPA implementation. You annotate your Java class with @entity, define fields, and Spring Boot handles all the SQL automatically. This means you rarely write raw SQL queries for standard operations.
12. What is a Spring Boot Repository and what is JpaRepository?
A Repository is an interface that handles database operations. JpaRepository is the most commonly used — it extends CrudRepository and provides methods like findAll(), findById(), save(), and deleteById() out of the box. You just extend it with your entity type and ID type and Spring Boot creates the implementation automatically.
@Repository
public interface UserRepository extends
JpaRepository<User, Long> {
List findByEmail(String email);
}
13. What is the difference between @PathVariable and @RequestParam?
@PathVariable extracts values from the URL path itself — like /users/42 where 42 is the ID. @RequestParam extracts values from query parameters — like /users?name=Mark. Use @PathVariable for identifying a specific resource and @RequestParam for filtering or optional inputs.
14. What is Spring Security and how do you add it to Spring Boot?
Spring Security is a framework for handling authentication and authorization in Spring applications. Adding spring-boot-starter-security to your project automatically secures all endpoints with a default login page. You customize it by extending SecurityFilterChain and defining which endpoints are public and which require authentication.
15. What is JWT and how is it used with Spring Boot?
JWT stands for JSON Web Token — a compact, self-contained token used for secure authentication. When a user logs in, your Spring Boot application generates a JWT and sends it to the client. The client sends this token in every subsequent request header. Spring Security validates the token on each request without needing to query the database. java// Adding JWT to Authorization header // Client sends this with every request: // Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...
16. What is the difference between @bean and @Component?
@Component is used on classes and lets Spring auto-detect them during component scanning. @bean is used on methods inside a @Configuration class when you need to manually define how a bean is created — useful for third-party classes you cannot annotate directly. Both result in Spring-managed beans but serve different use cases.
17. What is Actuator in Spring Boot?
Spring Boot Actuator provides production-ready monitoring endpoints for your application. After adding spring-boot-starter-actuator, you get endpoints like /actuator/health, /actuator/metrics, and /actuator/info automatically. TCS and Infosys interviewers ask about this because it shows awareness of production concerns beyond just writing code.
18. What is the difference between @RequestBody and @ResponseBody?@RequestBody tells Spring to deserialize the incoming HTTP request body (JSON) into a Java object. @ResponseBody tells Spring to serialize the returned Java object into JSON and write it to the HTTP response. When you use @RestController, @ResponseBody is applied automatically to every method.
@PostMapping("/users")
public User createUser(@RequestBody User user) {
return userService.save(user);
}
Conditional bean based on property:
@Bean
@ConditionalOnProperty(name = "feature.x.enabled", havingValue = "true")
public MyFeature myFeature() { ... }
19. What is a Microservice and how does Spring Boot support it?
A microservice is a small, independently deployable service that does one thing well. Instead of one large application, you build many small ones that communicate via REST APIs or messaging. Spring Boot is ideal for microservices because each service can be its own Spring Boot application — lightweight, independently deployable, and easy to scale.
**
**20. What is @Transactional and when do you use it?
@Transactional ensures that a group of database operations either all succeed or all fail together. If any operation inside the method throws an exception, Spring rolls back all changes automatically. You use it on service methods that perform multiple database operations — like transferring money between accounts.
@Transactional
public void transferMoney(Long fromId, Long toId, Double amount) {
accountRepository.debit(fromId, amount); accountRepository.credit(toId, amount); // If credit fails, debit is also rolled back
}
21. What is the difference between SOAP and REST?
REST is lightweight, uses HTTP methods (GET, POST, PUT, DELETE), and typically exchanges JSON. SOAP is a protocol with strict standards, uses XML, and is more complex. Modern applications including TCS and Infosys projects use REST almost exclusively. SOAP is still found in legacy banking and government systems.
22. What is Spring Boot DevTools?
DevTools is a dependency that improves developer experience by automatically restarting your application when code changes are detected. It also enables live reload in browsers and disables template caching during development. You add spring-boot-devtools to your project and it only activates in development — never in production.
23. What is the difference between findById() and getById() in JPA?
findById() returns an Optional — you must handle the case where the entity might not exist. getById() returns the entity directly but throws EntityNotFoundException if not found. Always prefer findById() in modern Spring Boot applications as it forces you to handle the missing case explicitly.
24. What is Lombok and why is it used in Spring Boot projects?
Lombok is a library that generates boilerplate code like getters, setters, constructors, and toString methods automatically using annotations. Instead of writing 50 lines of getters and setters, you add @data to your class and Lombok generates everything at compile time. It makes your entity and DTO classes much cleaner. java@Data
Example:
@Data
@Entity
public class User {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email; // No getters/setters needed — Lombok generates them
}
25. What is an Exception Handler in Spring Boot?
@ExceptionHandler lets you handle specific exceptions in a controller. @ControllerAdvice combined with @ExceptionHandler creates a global exception handler that catches exceptions across all controllers. This gives you one central place to return consistent error responses instead of scattering try-catch blocks everywhere.
@ControllerAdvice
public class GlobalExceptionHandler { @ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity handleNotFound(ResourceNotFoundException ex) {
return ResponseEntity.status(404).body(ex.getMessage());
}
}
26. What is the difference between PUT and PATCH?
PUT replaces the entire resource — you send the complete object with all fields. PATCH updates only the fields you send — useful when you want to change just one field without sending the entire object. In practice, most Indian IT company interviews expect you to know this difference for REST API design questions.
27. What is the use of @Value annotation?
@Value injects values from application.properties directly into your class fields. Instead of hardcoding configuration values in your code, you define them in properties files and inject them where needed. This makes your application configurable without changing code.
Simple Javafile:
@Service
public class EmailService {
@Value("${app.email.sender}")
private String senderEmail;
}
*28. What are common performance tuning tips for Spring Boot apps?
*
Use connection pooling (HikariCP defaults).
Tune JVM/Garbage Collector settings for production.
Enable caching (Spring Cache) for expensive operations.
Use async processing or reactive model where appropriate.
Limit component scanning scope and enable lazy initialization if startup time matters.
Enable lazy init:
spring.main.lazy-initialization=true
29. What is the difference between Spring Boot and Spring MVC?
Key changes:
Spring MVC is a web framework within Spring for building web applications following the Model-View-Controller pattern. Spring Boot is a tool that makes setting up Spring MVC (and any other Spring module) faster by providing auto-configuration and embedded servers. You almost always use both together — Spring Boot sets everything up and Spring MVC handles the web layer.
30. What is an Embedded Server in Spring Boot?
Spring Boot comes with an embedded Tomcat server by default — meaning you don't need to install or configure an external server. You just run your application as a plain Java program and the server starts automatically on port 8080. This makes deployment simple — you package everything into one JAR file and run it anywhere Java is installed.
Conclusion
You now have a compact, practice-ready collection of the top Spring Boot interview questions and answers. More than memorizing each response, focus on understanding the core concepts—how auto-configuration works, why starters exist, how DI and Spring Data simplify persistence, and how Actuator, security, and testing make applications production-ready. Interviewers care more about clear thinking and practical experience than perfectly recited definitions.
Quick next steps
Build a small CRUD service from scratch (use Spring Initializr) and add JPA, security, and Actuator.
Write unit and integration tests (use @SpringBootTest and relevant test slices).
Practice explaining trade-offs: when to use @ConfigurationProperties vs @Value, or monolith vs microservice.
Review a couple of real interview questions aloud to get comfortable with concise, structured answers.
Read the official Spring guides for any gaps and keep a sample repository you can demo.
Keep it simple, practice by building, and explain your thought process clearly during interviews. Good luck — you’ve got this!
Top comments (0)