How to import value from properties file and use it in annotation?

First: to inject values into a final field you have to use constructor injection see this question

This means that you pass some unknown value into the constructor.

Although the value never changes it is not constant, since the compiler cannot know this value, because its determined at runtime. And you can only use expressions as values of annotation whose value can be determined at compile time.

Thats because annotations are declared for a class not for a single instance and in your example the values of the variables are potentially diffrent for every instance.

So I would say, that what you want to achieve is not possible.

Leave a Comment