Last Updated: November 21, 2025
Spring Boot
Java framework for enterprise applications
Core Annotations
| Item | Description |
|---|---|
@SpringBootApplication
|
Main application entry point |
@RestController
|
REST API controller |
@Service
|
Business logic layer |
@Repository
|
Data access layer |
@Autowired
|
Dependency injection |
@Configuration
|
Configuration class |
@Bean
|
Define a bean |
REST API Example
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/{id}")
public ResponseEntity<User> getUser(@PathVariable Long id) {
return ResponseEntity.ok(userService.findById(id));
}
@PostMapping
public User createUser(@RequestBody User user) {
return userService.save(user);
}
}
Common Dependencies
| Item | Description |
|---|---|
spring-boot-starter-web
|
Web and REST APIs |
spring-boot-starter-data-jpa
|
JPA database access |
spring-boot-starter-security
|
Security features |
spring-boot-starter-test
|
Testing support |
Best Practices
- Use constructor injection over field injection
- Externalize configuration with application.properties
- Use DTOs for API responses
- Implement proper exception handling with @ControllerAdvice
💡 Pro Tips
Quick Reference
Use Spring Initializr to bootstrap new projects quickly