I have a class that is an entity:
Class.java
@Entity
public class Class {
@Id
@GeneratedValue
private Long id;
@NotNull
@Range(min = 0, max = 10)
private double value;
}
I want to get rid of the hard-coded values from the @Range
annotation and load them from a configuration file.
constraints.properties
minVal=0
maxVal=10
This is what I've tried:
@Component
@Entity
@PropertySource("classpath:/constraints.properties")
public class Class {
@Value("${minVal}")
private final long minValue;
@Value("${maxVal}")
private final long maxValue;
@Id
@GeneratedValue
private Long id;
@NotNull
@Range(min = minValue, max = maxValue)
private double value;
}
The error I get is attribute value must be constant
. How the initialization of these fields should be performed to get the result I want?