🧩 1.
Core Spring Boot Concepts
Q1. What is Spring Boot and how is it different from the Spring Framework?
Answer:
Spring Boot is an extension of the Spring framework that simplifies application development by
providing:
Auto-configuration (configures beans automatically based on classpath)
Embedded servers (Tomcat/Jetty/Undertow)
Production-ready features (Actuator, Metrics)
Opinionated defaults (no XML config)
Unlike traditional Spring, you don’t need extensive XML configuration or manual dependency setup.
Q2. What are Spring Boot starters?
Answer:
Starters are pre-defined dependency descriptors that simplify dependency management.
Example:
spring-boot-starter-web → includes Spring MVC + embedded Tomcat
spring-boot-starter-data-jpa → includes Spring Data JPA + Hibernate
These eliminate version conflicts and repetitive Maven configuration.
Q3. How does Spring Boot auto-configuration work?
Answer:
Auto-configuration uses:
@EnableAutoConfiguration
@ConditionalOnClass, @ConditionalOnMissingBean, etc.
Spring Boot scans the classpath and conditionally configures beans.
Example:
If spring-webmvc is found on the classpath, it configures a DispatcherServlet automatically.
Q4. How do you override Spring Boot auto-configuration?
Answer:
1. Define your own beans (Spring Boot won’t create them if already present).
2. Use @ConditionalOnMissingBean in your configs.
3. Exclude specific auto-configurations using:
4. @SpringBootApplication(exclude = [Link])
⚙️2. Spring Boot Annotations
Q5. Explain the use of key annotations in Spring Boot.
Annotation Purpose
Combines @Configuration, @EnableAutoConfiguration, and
@SpringBootApplication
@ComponentScan
@RestController Combines @Controller and @ResponseBody
@ConfigurationProperties Maps application properties to POJOs
@Value Injects values from properties/yaml
@EnableScheduling /
Enables and defines scheduled tasks
@Scheduled
@EnableAsync / @Async Enables asynchronous execution
3. Spring Data JPA and Persistence
Q6. How does Spring Boot simplify JPA/Hibernate integration?
Answer:
Auto-configures EntityManagerFactory and DataSource
Supports [Link] settings like:
[Link]=jdbc:mysql://localhost:3306/db
[Link]-auto=update
[Link]-sql=true
Supports CrudRepository, JpaRepository interfaces for easy data access.
Q7. What is the difference between CrudRepository, JpaRepository, and
PagingAndSortingRepository?
Repository Description
CrudRepository Basic CRUD operations
PagingAndSortingRepository Adds pagination and sorting
Adds JPA-specific features like flush(), batch operations, and @Query
JpaRepository
support
Q8. How do you handle transactions in Spring Boot?
Answer:
Using @Transactional annotation:
@Transactional
public void updateOrder(Order order) {
[Link](order);
Spring manages transaction boundaries automatically using AOP proxies.
☁️4. Microservices & Communication
Q9. How do microservices communicate in Spring Boot?
Answer:
1. Synchronous – via REST (using RestTemplate or WebClient)
2. Asynchronous – via message queues (Kafka, RabbitMQ)
3. Discovery – via Eureka or Consul
4. API Gateway – via Spring Cloud Gateway
Q10. What is Feign Client?
Answer:
Feign is a declarative REST client for calling other microservices easily.
Example:
@FeignClient(name = "order-service")
public interface OrderClient {
@GetMapping("/orders/{id}")
Order getOrder(@PathVariable Long id);
It auto-creates a proxy and handles REST calls, error decoding, etc.
🧠 5. Spring Boot Actuator & Monitoring
Q11. What is Spring Boot Actuator?
Answer:
Actuator provides production-ready endpoints for monitoring and managing applications.
Examples:
/actuator/health
/actuator/metrics
/actuator/env
You can customize which endpoints are exposed via:
[Link]=health,info,metrics
6. Exception Handling
Q12. How do you handle exceptions globally in Spring Boot?
Answer:
Using @ControllerAdvice and @ExceptionHandler:
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler([Link])
public ResponseEntity<String> handleNotFound(ResourceNotFoundException ex) {
return new ResponseEntity<>([Link](), HttpStatus.NOT_FOUND);
🧾 7. Security and Authentication
Q13. How do you secure a Spring Boot application?
Answer:
Using Spring Security:
Basic Auth (spring-boot-starter-security)
JWT Authentication
OAuth2
You configure access rules via:
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
[Link]().disable()
.authorizeHttpRequests()
.requestMatchers("/api/public/**").permitAll()
.anyRequest().authenticated()
.and()
.sessionManagement().sessionCreationPolicy([Link]);
return [Link]();
🧩 8. Advanced Topics for 6+ Years
Q14. What is the difference between RestTemplate and WebClient?
Feature RestTemplate WebClient
Type Blocking Non-blocking (Reactive)
Performance Slower under load Better for async calls
Library Spring MVC Spring WebFlux
Q15. How do you deploy a Spring Boot application?
Answer:
As a standalone JAR using java -jar [Link]
As a Docker container
In Kubernetes
On cloud platforms like AWS Elastic Beanstalk, Azure App Service, or GCP
🧩 9. Common Scenario-Based Questions
Q16. How do you handle configuration across environments (dev, test, prod)?
Answer:
Use profiles:
[Link]
[Link]
Activate using:
[Link]=prod
Q17. How do you ensure resilience in microservices?
Answer:
Circuit Breaker – Resilience4j or Hystrix
Retry Mechanism – Spring Retry
Fallbacks – handle service downtime gracefully
Timeouts + Bulkhead Pattern
Q18. How do you log effectively in Spring Boot?
Answer:
Use SLF4J with Logback:
private static final Logger log = [Link]([Link]);
[Link]("Processing order: {}", orderId);
Externalize log levels via:
[Link]=DEBUG
🧰 10. Practical Coding/Architecture Questions
1. How do you design an order-processing microservice using Spring Boot and Kafka?
2. How do you handle large file uploads efficiently?
3. How do you achieve API versioning in Spring Boot?
4. How do you secure internal microservice communication using JWT or API Gateway?
5. How do you tune performance for Hibernate queries and connection pooling?