Skip to content

Instantly share code, notes, and snippets.

View tokrug's full-sized avatar

Tomasz Krug tokrug

  • Wunderman Thompson Technology
  • Poznań, Poland
View GitHub Profile
@tokrug
tokrug / ConditionalOnConfigurationProperties.java
Last active January 21, 2024 00:20
Spring Boot autoconfiguration conditional annotation on typesafe ConfigurationProperies class. Maps properties to the provided class and executes it's isPresent() method to determine if Conditional should match or not. application.yml, ExampleSpringConfiguration.java and ExampleSpringPropertiesModel.java show how the rest of the code can be used.
/**
* Metannotation for OnConfigurationPropertiesCondition custom conditional implementation.
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnConfigurationPropertiesCondition.class)
public @interface ConditionalOnConfigurationProperties {
// properties namespace
@tokrug
tokrug / MethodHandleBenchmark.java
Created September 1, 2020 19:20
Reflections / Method handle / Lambda metafactory benchmark
import java.lang.invoke.CallSite;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;