This is very close to being a duplicate of How to import value from properties file and use it in annotation?, but I think there is a subtle difference between the questions.
You are trying to refer to a property in the @Column
annotation by using ${comment.length}
. What is really happening is that you try to assign the String
"${comment.length}"
to the length
attribute of the annotation. This is of course not allowed, it expects an int
.
Java, or Spring, can not "magically" replace ${propertyName}
with a property. Spring, however, has its own way of injecting property values:
@Value("${value.from.file}")
private String valueFromFile;
Even if your entity was a Spring bean (for example annotated with @Component
), and you injected the property with @Value
, it cannot be used in the annotation. This is because values in annotations need to be constant, and is explained in more detail in the accepted answer to the near duplicate question.
Now I'd like to use this constant:
It simply is not a constant, it is determined at runtime.