Spring Boot Overview
Spring Boot is a framework built on top of Spring that simplifies application development by
providing pre-configured defaults, starter dependencies, and embedded servers. Key points: - Built
on Spring Framework - Convention over Configuration - Spring Boot Starters for dependencies -
Embedded Tomcat/Jetty/Undertow - Actuator for monitoring
Important Annotations
@SpringBootApplication – Combines @Configuration, @EnableAutoConfiguration,
@ComponentScan @RestController – Combines @Controller + @ResponseBody @Autowired –
Dependency Injection @Component, @Service, @Repository – Bean stereotypes @Value – Read
properties @RequestMapping, @GetMapping, @PostMapping – API mappings @Entity, @Table,
@Id, @GeneratedValue – JPA Annotations
Spring Boot Starters
Examples: - spring-boot-starter-web: Spring MVC + Tomcat + JSON - spring-boot-starter-data-jpa:
JPA + Hibernate + JDBC - spring-boot-starter-security: Spring Security
Auto-Configuration
Automatically configures beans based on classpath dependencies and properties. Can be
customized via application.properties or application.yml.
Application Properties & Profiles
application.properties / application.yml: configuration files. Profiles: application-dev.properties,
application-prod.properties. Switch profile: --spring.profiles.active=dev
Spring Data JPA
Repository interfaces like JpaRepository, CrudRepository for CRUD operations without SQL.
Example: public interface UserRepository extends JpaRepository { List findByName(String name); }
Spring Boot Actuator
Provides endpoints for health, metrics, and info. Example: /actuator/health, /actuator/info
Exception Handling
@ControllerAdvice + @ExceptionHandler to handle exceptions globally.
Embedded Servers
Spring Boot apps run without an external server; embedded Tomcat runs inside.
Common Interview Q&A;
1. What is Spring Boot? Spring Boot is a Java-based framework for creating production-ready
Spring applications with minimal configuration. 2. Difference between Spring and Spring Boot?
Spring requires manual configuration; Spring Boot uses auto-configuration, starters, and embedded
servers. 3. What is @SpringBootApplication? Combines @Configuration,
@EnableAutoConfiguration, and @ComponentScan. 4. How does auto-configuration work? Uses
@EnableAutoConfiguration to configure beans based on classpath dependencies. 5. What is the
default server? Tomcat. 6. What is Spring Boot Starter? A dependency bundle for specific
functionality. 7. How to create REST API? Use @RestController and mapping annotations. 8. How
to connect to DB? Use spring-boot-starter-data-jpa + application.properties for datasource config. 9.
What are Profiles? Environment-specific configs. 10. Difference between @Controller and
@RestController? @Controller returns views; @RestController returns JSON/XML directly. 11.
How to handle exceptions globally? Using @ControllerAdvice + @ExceptionHandler. 12. How to
run on a different port? server.port=8081 in application.properties. 13. How does DI work? Spring
injects beans using @Autowired. 14. How to disable auto-configuration?
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) 15. What are
Actuators? Endpoints for monitoring. 16. How to secure REST API? Use Spring Security or JWT.