@CacheEvict(value = "users", allEntries = true) public void clearCache() { } } Scheduled Tasks @Configuration @EnableScheduling public class SchedulingConfig { } @Component public class ScheduledTasks {
@WebMvcTest(UserController.class) class UserControllerMvcTest { } spring boot in action
@Scheduled(cron = "0 0 * * * *") public void hourlyTask() { // Runs every hour } @CacheEvict(value = "users", allEntries = true) public void
@GetMapping("/{id}") public ResponseEntity<User> getById(@PathVariable Long id) { return userService.findById(id) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @CacheEvict(value = "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); }