spring-boot

java
package com.shop.inventory;

import jakarta.persistence.*;

@Entity
@Table(name = "inventory_item")

Optimistic Locking on Inventory Updates with @Version and a Retrying Conflict Handler in Spring Boot

spring-boot jpa hibernate
by codesnips 3 tabs
java
package com.example.demo.scheduled;

import com.example.demo.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;

Scheduled tasks with @Scheduled

java spring-boot scheduling
by David Kumar 2 tabs
java
package com.example.users.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;

Mapping JPA Entities to DTOs with a MapStruct Mapper Injected into a Spring Service

spring-boot mapstruct dto
by codesnips 4 tabs
java
package com.shop.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;

Guard a Checkout Endpoint with @PreAuthorize and a Custom PermissionEvaluator in Spring Boot

spring-boot spring-security authorization
by codesnips 3 tabs
java
package com.example.demo.service;

import com.example.demo.model.Order;
import com.example.demo.model.OrderItem;
import com.example.demo.model.User;
import com.example.demo.repository.OrderRepository;

Database transactions and isolation levels

java spring-boot transactions
by David Kumar 2 tabs
java
package com.example.auth.dto;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

Collect Bean Validation Field Errors in a Spring Boot Signup Endpoint

spring-boot bean-validation jakarta-validation
by codesnips 3 tabs
java
package com.example.fx.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;

Caching Currency-Conversion Rates in Spring Boot With @Cacheable and Scheduled Eviction

spring-boot caching caffeine
by codesnips 3 tabs
java
package com.example.security;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.io.Decoders;

Stateless JWT Authentication Filter and SecurityFilterChain in Spring Boot

java spring-boot spring-security
by codesnips 3 tabs
java
package com.shop.orders;

import jakarta.persistence.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.ArrayList;

Mapping a JPA Entity to a Response DTO with MapStruct in Spring Boot

spring-boot jpa mapstruct
by codesnips 4 tabs
java
package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

CORS configuration for cross-origin requests

java spring-boot cors
by David Kumar 2 tabs
java
package com.example.rates.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.web.client.RestTemplate;

Retrying a Flaky External API with Spring Retry @Retryable and @Recover Fallback

spring-boot spring-retry resilience
by codesnips 4 tabs
dockerfile
# Build stage
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /app

# Copy dependency definitions
COPY pom.xml .

Docker containerization for Spring Boot

java docker spring-boot
by David Kumar 3 tabs