Ahmet Karakaya
Ahmet Karakaya

Reputation: 10147

Spring @Value adding Validation less than

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

Upvotes: 3

Views: 2202

Answers (1)

Dawid Wysakowicz
Dawid Wysakowicz

Reputation: 3422

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;
   }
}

Upvotes: 6

Related Questions