vendredi 10 août 2018

Change a default annotation value for all usages

The @Timed annotation in Spring Boot (part of Micrometer) has several fields. One of these is:

double[] percentiles() default {};

I would like to set this value once across the entire codebase to a different array, say:

new double[] { 0.0, 50.0 };

This is achievable in one of two ways that I know of:

  1. Setting the field on every instance:

    @Timed(percentiles = new double[] { 0.0, 50.0 })
    
    
  2. Using @AliasFor to create a different annotation with the desired value.

I have also come across the AnnotationUtils class, but cannot see how to achieve my goal.

What is the standard way of doing this in Spring Boot? If it cannot be done in Spring Boot, how does one do it with the JDK's own reflection capabilities?





Aucun commentaire:

Enregistrer un commentaire