Spring Boot In Action [top] Now

@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LoggingInterceptor()) .addPathPatterns("/api/**"); } } @RestController public class ReactiveUserController { @GetMapping("/flux/users") public Flux<User> getAllReactive() { return userReactiveRepository.findAll() .delayElements(Duration.ofSeconds(1)); }

// Activate profile // --spring.profiles.active=dev,swagger Logback Configuration <!-- logback-spring.xml --> <configuration> <springProfile name="dev"> <root level="DEBUG"/> </springProfile> <springProfile name="prod"> <root level="INFO"/> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>logs/app.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>logs/app-%d{yyyy-MM-dd}.log</fileNamePattern> </rollingPolicy> </appender> </springProfile> </configuration> Structured Logging @Slf4j @Service public class OrderService { public void processOrder(Order order) { log.info("Processing order: {}", order.getId()); MDC.put("orderId", order.getId().toString()); try { // business logic } finally { MDC.clear(); } } } 10. Caching Enable Caching @Configuration @EnableCaching public class CacheConfig { @Bean public CacheManager cacheManager() { return new ConcurrentMapCacheManager("users", "products"); } } spring boot in action

@Test @Transactional @Rollback void databaseTest() { // Rollback after test } } @DataJpaTest class UserRepositoryTest { @Autowired private TestEntityManager entityManager; @Autowired private UserRepository repository; } getAll() { return ResponseEntity.ok(users)

public interface UserRepository extends JpaRepository<User, Long> { Optional<User> findByEmail(String email); @Query("SELECT u FROM User u WHERE u.email LIKE %:domain") List<User> findByEmailDomain(@Param("domain") String domain); } @Repository public class JdbcUserRepository { private final JdbcTemplate jdbcTemplate; public List<User> findAll() { return jdbcTemplate.query("SELECT * FROM users", (rs, rowNum) -> new User(rs.getLong("id"), rs.getString("email"))); } } MongoDB, Redis, etc. // MongoDB @Document(collection = "products") public class Product { } // Redis @RedisHash("sessions") public class UserSession { } 4. Web Development REST Controllers @RestController @RequestMapping("/api/users") public class UserController { @GetMapping public ResponseEntity<List<User>> getAll() { return ResponseEntity.ok(users); } } @CacheEvict(value = "users"

@CacheEvict(value = "users", allEntries = true) public void clearCache() { } } Scheduled Tasks @Configuration @EnableScheduling public class SchedulingConfig { } @Component public class ScheduledTasks {