Loading ...

Spring Boot Interview Questions & Answers (2025)

Spring Boot is a popular Java framework for building microservices and enterprise applications. Its auto-configuration, embedded servers, and starter dependencies make development faster and simpler. This guide covers 30 essential Spring Boot interview questions, with examples and explanations, suitable for both beginners and experienced developers.


1. What is Spring Boot?

Spring Boot is a framework built on top of Spring, designed to simplify application development. It provides auto-configuration, embedded servers, and starter dependencies.

@SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }

2. Difference between Spring and Spring Boot

FeatureSpringSpring Boot
SetupComplex, XML-basedAuto-configured, annotation-based
ServerRequires external serverEmbedded server (Tomcat, Jetty)
DeploymentWAR fileJAR file (standalone)
FocusGeneral-purpose frameworkRapid microservice development

3. What are Spring Boot Starters?

Starters simplify dependency management.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

4. Explain Spring Boot Auto-Configuration

Spring Boot auto-configures beans based on dependencies in the classpath.

@Bean public RestTemplate restTemplate() { return new RestTemplate(); }

5. What is @SpringBootApplication?

Combines:

  • @Configuration

  • @EnableAutoConfiguration

  • @ComponentScan

@SpringBootApplication public class MyApplication {}

6. Difference between @Component, @Service, @Repository, @Controller

AnnotationUsage
@ComponentGeneric bean definition
@ServiceBusiness/service layer
@RepositoryDAO layer, handles DB exceptions
@ControllerHandles HTTP requests

7. What is Spring Boot Actuator?

Provides monitoring and metrics.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>

Access health: http://localhost:8080/actuator/health


8. External Configuration

application.properties or application.yml:

server.port=9090 spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=root

9. @Value Annotation

Injects properties:

@Value("${server.port}") private int serverPort;

10. @RestController vs @Controller

AnnotationUsage
@ControllerReturns views (JSP, Thymeleaf)
@RestControllerReturns JSON/XML directly

11. Exception Handling

@ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(Exception.class) public ResponseEntity<String> handleException(Exception e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } }

12. Spring Boot DevTools

Provides hot reload and automatic restart.


13. Spring Boot Profiles

Environment-specific configs:

spring.profiles.active=dev

14. Spring Boot Security

@Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .anyRequest().authenticated() .and().httpBasic(); }

15. @EnableAutoConfiguration vs @SpringBootApplication

  • @EnableAutoConfiguration – auto-config only

  • @SpringBootApplication – combines auto-config, component scan, configuration


16. Embedded Server

java -jar myapp.jar

17. Spring Boot CLI

Run Groovy scripts:

spring run hello.groovy

18. Database Connection

spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=root spring.jpa.hibernate.ddl-auto=update

19. @Entity vs @Table

AnnotationUsage
@EntityMarks class as JPA entity
@TableMaps entity to a table

20. Spring Boot JPA Repositories

public interface UserRepository extends JpaRepository<User, Long> {}

21. Caching

@EnableCaching @SpringBootApplication public class MyApp {} @Cacheable("users") public User getUserById(Long id) { ... }

22. Scheduling

@EnableScheduling @Scheduled(fixedRate = 5000) public void runTask() { ... }

23. Testing

@SpringBootTest class MyAppTests { @Test void contextLoads() {} }

24. DevTools vs LiveReload

  • DevTools: auto-restart

  • LiveReload: browser refresh


25. Messaging

Supports Kafka, RabbitMQ:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency>

26. @RequestParam vs @PathVariable

AnnotationUsage
@RequestParamQuery parameters
@PathVariableURL path variables

27. File Upload

@PostMapping("/upload") public String uploadFile(@RequestParam("file") MultipartFile file) { ... }

28. Thymeleaf Example

@Controller public class MyController { @GetMapping("/home") public String home(Model model) { model.addAttribute("message", "Hello Spring Boot"); return "home"; // home.html } }

29. Spring Boot Starter POMs

  • spring-boot-starter-web

  • spring-boot-starter-data-jpa

  • spring-boot-starter-security


30. Packaging

  • JAR: java -jar target/myapp.jar

  • WAR: Deploy to external server

✍️ By Ashish | 2025-10-21T09:03:56.547Z

Call Our Course Advisors

IND: +91-98018 30173 / +91-70429 28331

US: +1-252 490 1033

UK: +44-121 3871751