java

java
package com.example.signup.validation;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

Custom @UniqueEmail Bean Validation Constraint in Spring Boot Signup

spring-boot bean-validation jsr380
by codesnips 4 tabs
java
package com.example.demo.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

Microservices with Spring Cloud

java spring-cloud microservices
by David Kumar 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
public final class Debouncer implements AutoCloseable {

    private final ScheduledExecutorService scheduler;
    private final long delayMillis;
    private final AtomicReference<ScheduledFuture<?>> pending = new AtomicReference<>();

Debouncing Rapid Method Calls in Java with a Scheduler and Cancellable Futures

java concurrency debounce
by codesnips 3 tabs
java
package com.example.demo.dto;

import java.time.LocalDateTime;
import java.util.List;

// Simple record

Record types for immutable data

java records immutable
by David Kumar 2 tabs
java
package com.example.demo.controller;

import com.example.demo.dto.PageResponse;
import com.example.demo.dto.UserDTO;
import com.example.demo.model.User;
import com.example.demo.service.UserService;

Pagination and sorting with Spring Data

java spring-data pagination
by David Kumar 2 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
package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.context.annotation.Bean;

Event-driven architecture with Spring Events

java spring-events event-driven
by David Kumar 4 tabs
java
package com.example.api.error;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.Instant;
import java.util.List;

Consistent JSON Error Responses with @RestControllerAdvice in Spring Boot

spring-boot rest-api error-handling
by codesnips 4 tabs
java
@Entity
@Table(name = "stored_files")
public class StoredFile {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

Spring Boot Multipart File Upload with Metadata Persistence and Validation

spring-boot multipart file-upload
by codesnips 3 tabs
java
package com.example.demo.model;

import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

Lombok for reducing boilerplate code

java lombok boilerplate
by David Kumar 1 tab
java
package com.example.demo.multitenancy;

public class TenantContext {
    private static final ThreadLocal<String> CURRENT_TENANT = new ThreadLocal<>();

    public static void setTenantId(String tenantId) {

Multi-tenancy for SaaS applications

java multi-tenancy saas
by David Kumar 4 tabs