#StackBounty: #java #spring #spring-boot Interface Annotation does not accept application.properties value

Bounty: 50

I have developed a simple Annotation Interface

public @interface CustomAnnotation {
    String foo() default "foo";

then I test it annotating a Class

   public class AnnotatedClass {

and call it using a method

public void foo()  {
    CustomAnnotation customAnnotation = AnnotatedClass.class.getAnnotation(CustomAnnotation.class);

and all works fine because it logs foo. I try also change the annotated class to @CustomAnnotation(foo = “123”) and all works fine too, becuase it logs 123.

Now I want that the value passed to the annotation is retrieved by the application.properties, so I have changed my annotated class to

@CustomAnnotation(foo = "${my.value}")
    public class AnnotatedClass {

but now the log returns the String “${my.vlaue}” and not the value in application.properties.

I know that is possible use ${} instruction in annotation because I always use a RestController like this @GetMapping(path = “${path.value:/}”) and all works fine.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.