Basics
1. What is Spring Boot?
Spring Boot is a framework that simplifies Spring application development by providing auto-configuration and embedded servers.
2. Difference between Spring and Spring Boot?
| Spring | Spring Boot |
|---|---|
| Requires manual configuration | Auto configuration |
| External server needed | Embedded server |
3. What is Auto Configuration?
Spring Boot automatically configures beans based on classpath dependencies.
4. What is Embedded Server?
Spring Boot provides Tomcat, Jetty, or Undertow inside the application.
Annotations
5. @SpringBootApplication
It combines @Configuration, @EnableAutoConfiguration and @ComponentScan.
6. @RestController
Used to create REST APIs.
@RestController
class TestController{
@GetMapping("/hello")
public String hello(){
return "Hello Spring Boot";
}
}
7. @Autowired
Used for dependency injection.
8. @RequestMapping vs @GetMapping
| @RequestMapping | @GetMapping |
|---|---|
| Supports all HTTP methods | Only GET |
Configuration
9. application.properties / application.yml
Used to configure database, server port, logging, etc.
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=1234
10. @Value annotation
@Value("${server.port}")
private String port;
11. Profiles
Used for different environments like dev, test, prod.
spring.profiles.active=dev
Database & JPA
12. What is Spring Data JPA?
Spring Data JPA provides repository support for database operations.
13. JpaRepository example
public interface UserRepo extends JpaRepository<User, Integer>{
}
14. @Entity example
@Entity
class User{
@Id
@GeneratedValue
int id;
String name;
}
15. Hibernate vs JPA
| Hibernate | JPA |
|---|---|
| ORM tool | Specification |
Exception Handling
16. @ExceptionHandler
@ExceptionHandler(Exception.class)
public String handle(){
return "Error occurred";
}
17. @ControllerAdvice
Global exception handler.
Security
18. What is Spring Security?
Provides authentication and authorization.
19. JWT in Spring Boot
Used for token-based authentication.
Microservices
20. What is Microservices?
Application divided into small independent services.
21. Eureka Server
Service registry for microservices.
22. API Gateway
Single entry point for microservices.
Actuator
23. What is Spring Boot Actuator?
Provides monitoring and health endpoints.
/actuator/health
/actuator/metrics
Testing
24. @SpringBootTest
Used for integration testing.
25. @MockBean
Used to mock dependencies.