java

java
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

import Transaction.Category;

Grouping and Summarizing Transactions with Java Stream Collectors

java streams collectors
by codesnips 3 tabs
java
package com.shop.orders.events;

import java.math.BigDecimal;
import java.time.Instant;

public record OrderPlacedEvent(

Transactional Domain Events With Spring's ApplicationEventPublisher and @TransactionalEventListener

spring spring-boot domain-events
by codesnips 4 tabs
java
package com.example.search;

import java.time.LocalDate;

@ValidDateRange
public class DateRangeSearch {

Bind and Validate a Date-Range Search with @ModelAttribute and a Custom PropertyEditor

spring-boot spring-mvc data-binding
by codesnips 4 tabs
java
package com.example.tracing;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;

Propagate a Correlation ID Through Servlet Requests With MDC and a Feign Interceptor

java servlet filter
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/notifications")
public class NotificationController {

    private final SseEmitterRegistry registry;
    private final NotificationService service;

Push Live Notifications with Server-Sent Events in Spring Boot

spring-boot sse server-sent-events
by codesnips 3 tabs
java
@Entity
@Table(name = "idempotency_records",
       uniqueConstraints = @UniqueConstraint(columnNames = "idempotency_key"))
public class IdempotencyRecord {

    public enum Status { IN_PROGRESS, COMPLETED }

Idempotent POST Handling in Spring Boot with a Stored Idempotency-Key

spring-boot idempotency rest-api
by codesnips 3 tabs
java
import org.springframework.hateoas.RepresentationModel;
import java.math.BigDecimal;

public class ProductModel extends RepresentationModel<ProductModel> {

    private final Long id;

Cursor-Based Pagination with HATEOAS Links in Spring Data REST

spring-boot spring-data-jpa hateoas
by codesnips 4 tabs
lua
-- KEYS[1] = bucket key
-- ARGV[1] = capacity, ARGV[2] = refill_rate (tokens/sec)
-- ARGV[3] = now_ms, ARGV[4] = requested tokens
local capacity    = tonumber(ARGV[1])
local refill_rate = tonumber(ARGV[2])
local now_ms      = tonumber(ARGV[3])

Token Bucket Rate Limiting in a Servlet Filter with Redis and Lua

rate-limiting token-bucket servlet
by codesnips 3 tabs
java
package com.example.health;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

Custom Spring Boot HealthIndicator for Queue Depth on /actuator/health

spring-boot actuator health-check
by codesnips 4 tabs
java
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import java.time.Instant;

@MappedSuperclass
public abstract class SoftDeletable {

Soft-Delete JPA Entities with Hibernate @Where and a Restore-Capable Repository

spring spring-data hibernate
by codesnips 4 tabs
java
package com.example.demo.controller;

import com.example.demo.dto.UserDTO;
import com.example.demo.dto.v2.UserDTOV2;
import com.example.demo.service.UserService;
import org.springframework.web.bind.annotation.*;

API versioning strategies

java spring-boot api-versioning
by David Kumar 4 tabs
java
@Configuration
public class TxConfig {

    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        DataSourceTransactionManager tm = new DataSourceTransactionManager(dataSource);

Multi-Step Order Flow With Spring TransactionTemplate and Savepoint Rollback

spring-boot transactions transactiontemplate
by codesnips 3 tabs