spring

java
package com.shop.shipping;

import java.math.BigDecimal;

public interface ShippingCostCalculator {

Runtime Strategy Selection for Shipping-Cost Calculators via a Factory

strategy-pattern factory-pattern design-patterns
by codesnips 4 tabs
java
package com.example.cache;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicBoolean;

Single-Flight Cache Loader: Coalesce Concurrent Identical Loads in Java

caching concurrency single-flight
by codesnips 3 tabs
java
package com.example.security;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

Method-Level Role Authorization with a Custom @RequireRole Annotation and Spring AOP

spring spring-boot aop
by codesnips 4 tabs
java
package com.example.feed;

import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Base64;

Keyset (Cursor) Pagination with Spring Data JPA and Base64 Cursors

spring spring-data jpa
by codesnips 3 tabs
java
package com.shop.orders.events;

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

public final class OrderPlaced {

Publishing and Consuming an OrderPlaced Domain Event with Spring's ApplicationEventPublisher

java spring-boot spring
by codesnips 4 tabs
java
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Time-Based Caffeine Cache for Expensive Currency Rate Lookups in Spring

caffeine caching spring
by codesnips 3 tabs
java
@Configuration
@EnableScheduling
@EnableConfigurationProperties(CleanupProperties.class)
public class SchedulingConfig {

    @Bean(destroyMethod = "shutdown")

Recurring Cleanup Job with Spring @Scheduled and a Shutdown-Aware Executor

spring spring-boot scheduling
by codesnips 3 tabs
java
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;

import java.math.BigDecimal;

Deserialize Polymorphic JSON into a Sealed Interface Hierarchy with Jackson

jackson json deserialization
by codesnips 3 tabs
java
@Entity
@Table(name = "invoices")
@FilterDef(
    name = "tenantFilter",
    parameters = @ParamDef(name = "tenantId", type = String.class)
)

Per-Tenant Row Filtering with Hibernate @Filter Enabled Per Request

hibernate jpa multi-tenancy
by codesnips 4 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.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
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