Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring @Value adding Validation less than

Tags:

java

spring

I using the following property value injection. How I can add a less than validation to this operation. I mean I want to set a validation the user.maxpassiveday property value has not to be less than 100 lets say.

  @Value("${user.maxpassiveday}")
   int maxpassiveday;

Using Spring 3.1.1 version

like image 920
Ahmet Karakaya Avatar asked Dec 06 '25 05:12

Ahmet Karakaya


1 Answers

You can also use @Value on setter method:

int maxpassiveday;

@Value("${user.maxpassiveday}")
public void setMaxPassiveDay(final String maxpassiveday) {
   int tmp = Integer.parseInt(maxpassiveday);
   if (tmp < 100) {
      this.maxpassiveday = tmp;
   }
}
like image 73
Dawid Wysakowicz Avatar answered Dec 07 '25 18:12

Dawid Wysakowicz