I have a spring component that validates the values of an Entity Class,
One of the variables has a Custom Annotation whose values are supposed to be loaded from the property file, currently it says that Attribute must be constant
Here is the sample code.
I know that Spring allows to fetch properties like this
@Value("${allowedNames}")
private String names;
But I have an entity with one of the variables annotated by custom validator interface i.e. @NameValidationDefinition
. I would like to pass the values from the properties file to the annotation but it gives compile time error that Attribute must be Constant which I understand as I know that
Annotations take only constants or final and static declared primitives or Strings
public Class Person {
@NameValidationDefinition(values = names)
private String name;
}
What I want to know is that is there a workaround for this to make it work?
The value from the properties file is by default casted to String but still when I create the Entity and initialize the variable as static final and pass the String in the Constructor, I get the same compile time error.
I would appreciate any kind of help on this.