Spring Boot In Action (2026)

public void publish(Order order) { rabbitTemplate.convertAndSend("order.exchange", "order.created", order); } }

@Component @RabbitListener(queues = "order.queue") public class OrderListener { @RabbitHandler public void handleOrder(Order order) { System.out.println("Received order: " + order.getId()); } } File Upload @PostMapping("/upload") public ResponseEntity<String> handleUpload(@RequestParam("file") MultipartFile file) throws IOException { Path path = Paths.get("uploads/" + file.getOriginalFilename()); Files.write(path, file.getBytes()); return ResponseEntity.ok("File uploaded successfully"); } // Async file processing @Async public CompletableFuture<String> processFile(MultipartFile file) { // Process large files asynchronously } 14. Error Handling Global Exception Handler @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public Map<String, String> handleValidation(MethodArgumentNotValidException ex) { return ex.getBindingResult().getFieldErrors().stream() .collect(Collectors.toMap( FieldError::getField, FieldError::getDefaultMessage )); } spring boot in action

@Service public class UserService { @Cacheable(value = "users", key = "#id") public User findById(Long id) { return userRepository.findById(id).orElseThrow(); } public void publish(Order order) { rabbitTemplate