0% found this document useful (0 votes)
24 views

Spring Boot Interview Document

Spring boot Interview Preparation

Uploaded by

BADR EL KHALYLY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Spring Boot Interview Document

Spring boot Interview Preparation

Uploaded by

BADR EL KHALYLY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

The Ultimate Spring Boot Interview Preparation Guide

Basics of Spring Boot


1. What is Spring Boot and why is it used?

Spring Boot simplifies Java development by offering auto-configuration, embedded


servers, and production-ready features.

Example:

@SpringBootApplication

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

2. What are the main features of Spring Boot?

• Auto-Configuration

• Embedded Servers

• Actuator

• Starter Dependencies

• CLI and DevTools

3. What are Spring Boot starters?

Starters are dependency descriptors to simplify build configuration.

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

4. Explain @SpringBootApplication annotation.

Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan.

5. How to create a Spring Boot application?


• Using @SpringBootApplication

• Spring Initializr

• Spring Boot CLI

• Maven/Gradle setup

Spring Boot Configuration


6. How to configure Spring Boot using application.properties?

server.port=8080

spring.datasource.url=jdbc:mysql://localhost:3306/mydb

7. Difference between application.properties and application.yml?

• .properties: Key-value format.

• .yml: Hierarchical, better for complex configs.

8. How to externalize configuration?

• application.properties/yml

• Environment Variables

• Command Line Arguments

• Spring Profiles

• Config Server

9. What is @Value used for?

@Value("${property.name}")

private String propertyName;

10. What are Spring Profiles and how do they work?

Used for environment-specific configurations.

spring.profiles.active=dev

Spring Boot RESTful Web Services


11. What is @RestController?

Combines @Controller and @ResponseBody.

12. How to create a simple RESTful API?

@RestController
@RequestMapping("/api")

public class Controller {

@GetMapping("/hello")

public String hello() {

return "Hello!";

13. How to handle HTTP methods GET, POST, PUT, DELETE?

Use @GetMapping, @PostMapping, @PutMapping, @DeleteMapping.

14. What is @RequestBody and @ResponseBody?

• @RequestBody: Maps HTTP request body to Java object.

• @ResponseBody: Maps Java object to HTTP response body.

15. How to handle query parameters?

@GetMapping("/users")

public List<User> getUsers(@RequestParam String name) {...}

Data Access with Spring Boot


16. How to connect Spring Boot with a database?

Use spring-boot-starter-data-jpa.

17. How to configure multiple databases?

Define multiple datasources and entity managers.

18. What is Spring Data JPA?

Simplifies database interactions via repositories.

19. What is @Entity?

@Entity

public class User {

@Id

private Long id;

}
20. What is @Repository?

Specialization of @Component for DAO classes.

21. What is @Transactional?

Ensures operations are executed within a transaction.

Spring Boot Security


22. Ways to implement security?

• Spring Security

• Basic Auth

• JWT

• OAuth2

• LDAP

• Method-Level Security

23. How to enable Spring Security?

Add spring-boot-starter-security dependency.

24. What is @EnableWebSecurity?

Enables web security configuration.

25. How to handle authentication and authorization?

Configure HttpSecurity for roles and auth.

26. What is Basic Authentication?

Send username and password in HTTP headers.

27. How to configure form-based login?

Use http.formLogin().loginPage("/login").permitAll();

Spring Boot Testing


28. What is @SpringBootTest?

Loads full application context for integration testing.

29. How to test REST controllers?

Use @WebMvcTest or @SpringBootTest.

30. What is @MockBean?


Mocks a bean in the application context.

31. How to test service layers?

Use @MockBean to mock dependencies.

32. How to handle exceptions?

@ControllerAdvice

public class ExceptionHandler {

@ExceptionHandler(Exception.class)

public ResponseEntity<String> handle(Exception ex) {

return new ResponseEntity<>(ex.getMessage(),


HttpStatus.INTERNAL_SERVER_ERROR);

Advanced Topics
33. What is Spring Boot Actuator?

Provides production-ready endpoints.

34. How to create a custom starter?

Define auto-configuration and add it to META-INF/spring.factories.

35. What is DevTools?

Automatic restart, live reload, enhanced debugging.

36. How to change server port?

Set server.port in properties.

37. Microservices support?

Seamless integration with Spring Cloud.

Spring Boot and Cloud


38. What is Spring Cloud?

Tools for microservice patterns: config management, service discovery.

39. Using Eureka?

Add Eureka client dependency and annotate with @EnableDiscoveryClient.


40. What is Spring Cloud Config?

Centralized external configuration.

41. Integrating with Kafka?

Use spring-kafka starter.

42. Spring Boot with Docker?

Create a Dockerfile, build an image, deploy container.

Miscellaneous
43. Scheduling tasks?

Use @EnableScheduling and @Scheduled.

44. Default logging framework?

Logback.

45. Enabling SSL?

Configure server.ssl properties.

46. What is @ComponentScan?

Scans packages for Spring components.

47. Handling asynchronous processing?

Use @EnableAsync and @Async.

Spring Boot Security


48. What is Spring Security?

Authentication and authorization framework.

49. Enabling Spring Security?

Add spring-boot-starter-security dependency.

50. Default username and password?

Username: user, Password: generated at startup.

51. Custom login page?

Configure with formLogin().loginPage("/login").

52. Method-Level Security?

Secure methods with @PreAuthorize, @Secured.


53. What is JWT?

Compact token format for stateless authentication.

54. Basic Authentication implementation?

Configure HttpSecurity with httpBasic().

55. What is CSRF protection?

Defends against cross-site request forgery attacks.

56. What is OAuth2?

Protocol for secure delegated access.

57. LDAP Integration?

Use spring-boot-starter-ldap.

Messaging in Spring Boot


58. Messaging support?

JMS, AMQP, Kafka, RabbitMQ.

59. Configuring a message broker?

Add RabbitMQ/Kafka starters and configure properties.

60. Sending and receiving RabbitMQ messages?

Use RabbitTemplate and @RabbitListener.

61. What is Spring Kafka?

Spring integration with Apache Kafka.

62. Kafka Producer/Consumer config?

Set bootstrap-servers, group-id in application.properties.

Reactive Programming
63. What is Reactive Programming?

Handle asynchronous data streams non-blockingly.

64. What is WebFlux?

Reactive alternative to Spring MVC.

65. What are Mono and Flux?

Mono = 0 or 1 value, Flux = 0 to N values.


66. @GetMapping in WebFlux?

Return Mono or Flux from controller.

67. Handling exceptions in WebFlux?

Use @ExceptionHandler and @ControllerAdvice.

68. @ResponseStatus in WebFlux?

Set HTTP status for a method or exception.

Spring Boot with Cloud


69. What is Spring Cloud?

Framework for building resilient distributed systems.

70. Using Eureka for discovery?

Add dependency, annotate with @EnableDiscoveryClient.

71. What is Spring Cloud Config?

Centralized configuration server.

72. Configure Spring Boot with Config Server?

Use @EnableConfigServer and point clients to it.

73. What is Spring Cloud Gateway?

API Gateway for routing requests.

74. Load balancing with Ribbon?

Use @LoadBalanced RestTemplate.

75. Circuit Breaker (Hystrix, Resilience4J)?

Prevents cascading failures.

76. Docker deployment?

Package app into Docker image and deploy.

Miscellaneous Topics
77. Monitoring Spring Boot apps?

Use Actuator + Prometheus + Grafana.

78. Using Redis/MongoDB?

Use starters like spring-boot-starter-data-redis/mongodb and configure properties.


This completes your full Spring Boot 78 Questions & Answers Interview
Preparation Guide!

You might also like