title: Spring MVC validation ignored
body: <p>I have Spring MVC app on Tomcat. I'm trying to add validation in it.
  For some reason my validation is ignored and not checked.</p>
  
  <p>Here is my POJO</p>
  
  <pre><code>import org.hibernate.validator.constraints.Range;
  public class Goal {
  
      @Range(min = 1, max = 15)
      private int minutes;
  
      public int getMinutes() {
          return minutes;
      }
  
      public void setMinutes(int minutes) {
          this.minutes = minutes;
      }
  }
  </code></pre>
  
  <p>And controller</p>
  
  <pre><code>import org.springframework.validation.BindingResult;
  import javax.validation.Valid;
  
  @Controller
  @SessionAttributes("goal")
  public class GoalController {
  
      @RequestMapping(value = "addGoal", method = RequestMethod.POST)
      public String updGoal(@ModelAttribute("goal") @Valid Goal goal, BindingResult result) {
          System.out.println(goal.getMinutes());
  
          System.out.println(result.hasErrors());
  
          if(result.hasErrors()) {
              return "addGoal";
          }
  
          return "redirect:addMinutes.html";
      }
  }
  </code></pre>
  
  <p>But even if I try to put any negative values as "minutes" there no errors produced.</p>
  
  <p><strong>Added configuration</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:p="http://www.springframework.org/schema/p"
         xsi:schemaLocation="
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;mvc:annotation-driven/&gt;
      &lt;context:component-scan base-package="com.xlab.ice.mvc.controller"/&gt;
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt;
  
      &lt;mvc:resources mapping="/pdfs/**" location="pdf"/&gt;
  
      &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages"/&gt;
  
      &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/&gt;
  
      &lt;mvc:interceptors&gt;
          &lt;bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/&gt;
      &lt;/mvc:interceptors&gt;
  
      &lt;bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0"/&gt;
  
  &lt;/beans&gt;
  </code></pre>