title: @Min and @Max validation is not working of hibernate validator package in spring boot
body: <p>@Min and @Max validator is not working as the value is getting assigned to a static variable from the properties file. But it taking all the value and not validating.</p>
  <p><strong>OTPLengthAndExpiryDetail.java</strong></p>
  <pre><code>package com.custom.store.sms.twillo.model;
  
  import javax.validation.constraints.Max;
  import javax.validation.constraints.Min;
  import javax.validation.constraints.NotNull;
  
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.stereotype.Component;
  import org.springframework.validation.annotation.Validated;
  
  @Component
  @Validated
  public class OTPLengthAndExpiryDetail {
      
      @Min(value = 4 , message = &quot;Value should be greater then then equal to 4&quot;)
      @Max(value = 6 , message = &quot;Value should be less then then equal to 6&quot;)
      @NotNull(message = &quot;It can not be null. Please provide no. in b/w 4 to 6&quot;)
      @Value(&quot;${otp.length}&quot;)
      private static Integer length;
      
      @Min(value = 20 , message = &quot;Value should be greater then equal to 20&quot;)
      @Max(value = 180 , message = &quot;Value should be less then equal to 180&quot;)
      @NotNull(message = &quot;It can not be null. Please provide no. in b/w 20 to 300&quot;)
      @Value(&quot;${otp.expiryTime}&quot;)
      private static Integer expiryTime;
  
      public static Integer getLength() {
          return length;
      }
  
      public void setLength(Integer length) {
          OTPLengthAndExpiryDetail.length = length;
      }
  
      public static Integer getExpiryTime() {
          return expiryTime;
      }
  
      public void setExpiryTime(Integer expiryTime) {
          OTPLengthAndExpiryDetail.expiryTime = expiryTime;
      }
      
  }
  
  </code></pre>
  <p><strong>application.properties</strong></p>
  <pre><code>#1. ################       DB DETAILS        ###############################
  spring.jpa.hibernate.ddl-auto=update
  spring.datasource.url=jdbc:mysql://remotemysql.com/q5UV1n69DW?useSSL=false
  spring.datasource.username=q5
  spring.datasource.password=ur
  ############################################################################
  
  
  
  #2. ##############     LOGGING DETAILS FOR APPLICATION     #################
  spring.h2.console.enabled=true
  #logging.level.org.hibernate=debug
  spring.jpa.show-sql=true
  ############################################################################
  
  
  
  #3.###############       TWILLO DETAILS FOR OTP      #######################
  #both below twillo details can't be null                        
  twilio.accountSID=AC53bec33dc8bae99f8                                     
  twilio.authId=7c31ef0e28e75473
  twilio.phoneNumber=16468634753                    
  ############################################################################
  
  
  
  #4.###############     OTP CONFIGURATION DETAILS     #######################
  #otp.length can not be null. Please provide no. in b/w 4 to 6
  otp.length=4
  #otp.expirytime can not be null. Please provide no. in b/w 20 to 300
  otp.expiryTime=2000
  otp.message=your otp is 
  ############################################################################
  
  </code></pre>
  <p><strong>build.gradle</strong></p>
  <pre><code>plugins {
      id 'org.springframework.boot' version '2.3.3.RELEASE'
      id 'io.spring.dependency-management' version '1.0.10.RELEASE'
      id 'java'
  }
  
  group = 'com.custom.store'
  version = '0.0.1-SNAPSHOT'
  sourceCompatibility = '1.8'
  
  configurations {
      compileOnly {
          extendsFrom annotationProcessor
      }
  }
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      implementation 'org.springframework.boot:spring-boot-starter-web'
      implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
      implementation group: &quot;com.twilio.sdk&quot;, name: &quot;twilio&quot;, version : &quot;7.47.2&quot;
      implementation('org.springframework.boot:spring-boot-starter-validation')
      runtimeOnly 'mysql:mysql-connector-java'
      compileOnly 'org.projectlombok:lombok'
      //implementation &quot;org.hibernate:hibernate-validator:6.1.5.Final&quot;
      annotationProcessor 'org.projectlombok:lombok'
      testImplementation('org.springframework.boot:spring-boot-starter-test') {
          exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
      }
  }
  
  test {
      useJUnitPlatform()
  }
  
  </code></pre>
  <p><strong>OTPProperties.java</strong> *  it is the class where I am instantiating the custom Configuration*</p>
  <pre><code>package com.custom.store.sms.twillo.conf;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.stereotype.Component;
  import org.springframework.validation.annotation.Validated;
  
  import com.custom.store.sms.twillo.model.OTPLengthAndExpiryDetail;
  import com.custom.store.sms.twillo.model.TwilioAccountAndAuthDetail;
  
  
  @Component
  @ConfigurationProperties
  @PropertySource(&quot;classpath:application.properties&quot;)
  public class OTPProperties {
      
      //@Autowired
      TwilioAccountAndAuthDetail twilio;
      
      //@Autowired
      OTPLengthAndExpiryDetail otp;
  
      public TwilioAccountAndAuthDetail getTwilio() {
          return twilio;
      }
  
      public void setTwilio(TwilioAccountAndAuthDetail twilio) {
          this.twilio = twilio;
      }
  
      public OTPLengthAndExpiryDetail getOtp() {
          return otp;
      }
  
      public void setOtp(OTPLengthAndExpiryDetail otp) {
          this.otp = otp;
      }
      
  }
  
  </code></pre>