I would like to put the value of a spring boot environment variable into a validation annotation (@Min, @Max), but i don't know how to do it. Here is my code :
public class MessageDTO {
@Value("${validationMinMax.min}")
private Integer min;
@JsonProperty("Message_ID")
@NotBlank(message = "messageId cannot be blank.")
@Pattern(regexp = "\\w+", message = "messageId don't suits the pattern")
private String messageId;
@JsonProperty("Message_Type")
@NotBlank(message = "messageType cannot be blank")
private String messageType;
@JsonProperty("EO_ID")
@NotBlank(message = "eoId cannot be blank")
private String eoId;
@JsonProperty("UI_Type")
@NotNull(message = "uiType cannot be null")
@Min(1)
@Max(3)
private Integer uiType;
And here is my application.yml :
server:
port: 8080
spring:
data:
cassandra:
keyspace-name: message_keyspace
port: 9042
contact-points:
- localhost
validationMinMax:
min: 1
max: 3
I would like to put the field "min" and "max" of my yml into the annotation field @Min() and @Max() of my attribute uiType. Does anyone knows how to do it ? Thanks in advance for your help !