title: Spring 3 MVC Validation is not working
body: <p>I'm trying to use simple form validation. When I enter wrong data, method hasErrors always return false. Could you please help find the problem?</p>
  
  <p>Part from Controller:</p>
  
  <pre><code>    @RequestMapping(value = "/measure", method = RequestMethod.POST)
  public String updateMeasure(@Valid @ModelAttribute("measure") Measure measure, BindingResult result){
      System.out.println("result has errors: " + result.hasErrors());
      System.out.println("updated measure: " + measure.getWeight());
      if(result.hasErrors()){
          return "measure";
      }
      return "redirect:measure";
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public class Measure {
  
  @Range(min = 1, max = 70)
  private int weight;
  
  public int getWeight() {
      return weight;
  }
  
  public void setWeight(int weight) {
      this.weight = weight;
  }}
  </code></pre>
  
  <p>Part of servlet-config.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;mvc:default-servlet-handler/&gt;
  &lt;mvc:annotation-driven/&gt;
  &lt;context:component-scan base-package="ru.kidstat"/&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/views/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>pom.xml dependencies:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- Servlet API and JSTL --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;3.0.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;jstl&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Validation --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;4.2.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre><code>    &lt;servlet&gt;
      &lt;servlet-name&gt;kidstatServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/config/servlet-config.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;kidstatServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>