Skip to content

Instantly share code, notes, and snippets.

View aoudiamoncef's full-sized avatar
🏠
Working from home

Moncef AOUDIA aoudiamoncef

🏠
Working from home
View GitHub Profile
@aoudiamoncef
aoudiamoncef / BigDecimalConverter.java
Last active April 24, 2024 08:23
BigDecimal Scale 2 && RoundingMode.HALF_UP Hibernate Converter
package com.maoudia;
import java.math.BigDecimal;
import java.math.RoundingMode;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
@Converter(autoApply = true)
public class BigDecimalConverter implements AttributeConverter<BigDecimal, BigDecimal> {
@aoudiamoncef
aoudiamoncef / ErrorResource.java
Last active February 27, 2024 10:31
Spring Boot Error Server Error Configuration
package com.maoudia;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ErrorResource {
/**
@aoudiamoncef
aoudiamoncef / ErrorResource.java
Created February 27, 2024 10:19
Spring Boot Error Server Error Configuration
package com.maoudia;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ErrorResource {
/**
@aoudiamoncef
aoudiamoncef / FakeUserRepository.java
Last active February 25, 2024 23:31
Spring Boot with Reactor Disposable, Disposable.Composite and Disposable.Swap
package com.maoudia;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
@aoudiamoncef
aoudiamoncef / README.md
Last active June 12, 2024 10:11
Spring Boot Logback Async Logging

Spring Boot Logback Async Logging

Overview

This gist demonstrates configuring asynchronous logging with Logback in a Spring Boot application. This approach provides improved performance, reduced latency, scalability, and fault tolerance.

By leveraging existing Spring logging configuration properties, we can customize the logging behavior according to your application's requirements seamlessly based on the envirement variables declared in defaults.xml. See Custom log configuration

Important

Contrary to the default configuration, file logging (ASYNC_FILE) is enabled even if logging.file.name or logging.file.path are not used.

@aoudiamoncef
aoudiamoncef / AppConfig.java
Last active March 9, 2024 06:33
Spring Boot Custom Bean Validations with Jakarta ConstraintValidator, Grouping Validation Constraints, GroupSequence and i18n messages
package com.maoudia;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
/**
* The {@code AppConfig} class configures beans for message source and validator factory.
@aoudiamoncef
aoudiamoncef / AppProperties.java
Last active May 31, 2024 07:49
Spring Boot Custom Configuration Properties With Java Records + Validations + Metadata
package com.maoudia;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.validation.annotation.Validated;
import java.net.URI;
@aoudiamoncef
aoudiamoncef / IntegrationTest.java
Last active February 9, 2024 10:50
Spring Boot Custom Test Annotations
package com.maoudia;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.TestPropertySource;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@aoudiamoncef
aoudiamoncef / JsonPatchUtils.java
Last active February 6, 2024 08:35
JSON Patch and JSON Merge Patch to objects using Jackson
package com.maoudia;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gravity9.jsonpatch.JsonPatch;
import com.gravity9.jsonpatch.JsonPatchException;
import com.gravity9.jsonpatch.mergepatch.JsonMergePatch;
import jakarta.validation.constraints.NotNull;
@aoudiamoncef
aoudiamoncef / README.md
Last active February 15, 2024 20:47
Reactor "expand" and "expandDeep" in action

When exploring directory structures in a reactive programming environment, the strategies of breadth-first and depth-first traversal play a crucial role. In the context of the ReactorFileUtils class, these strategies are employed by the expand and expandDeep methods to traverse and emit paths in a reactive stream. Let's delve into these strategies and understand how they work:

Breadth-First (expand Method):

Breadth-First (expand)

       A
     /   \
    B     C