title: Spring MVC, Hibernate Validation, Form request is not validated
body: <p>I need some help about validations in spring mvc 4.3 and hibernate.
  I have imported "hibernate-validator-6.0.3.Final.jar" and "validation-api-2.0.0.Final.jar" (part of "hibernate-validator-6.0.3.Final.jar").</p>
  
  <p><strong>When i fill form with data (username and password), username and password is not validated so request point to index</strong></p>
  
  <p><strong>User.java</strong></p>
  
  <pre><code>package invoice.user;
  
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  public class User {
  
      @NotNull(message = "required")
      @Size(min = 3, max = 50, message = "Username incorrect")
      private String username;
  
      @NotNull(message = "required")
      @Size(min = 3, max = 50, message = "Password incorrect")
      private String password;
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      @Override
      public String toString() {
          return "User{" +
                  "username='" + username + '\'' +
                  ", password='" + password + '\'' +
                  '}';
      }
  }
  </code></pre>
  
  <p><strong>UserController.java</strong></p>
  
  <pre><code>package invoice.user;
  import org.springframework.stereotype.Controller;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import javax.validation.Valid;
  
  @Controller
  public class UserController {
  
      @RequestMapping("/")
      public String showLoginPage(@ModelAttribute("user") User user){
          return "user/user-login";
      }
  
      @RequestMapping(value = "/login", method = RequestMethod.POST)
      public String processLoginForm(@Valid @ModelAttribute("user") User user, BindingResult results){
          if(results.hasErrors()){
              return "user/user-login";
          }
              return "user/index";
      }
  }
  </code></pre>