title: Hibernate Validator 5.1.1 is not working in Web application
body: <p>I am using Spring 4.0 and latest Spring Security in my Web application. I want to use the Hibernate validation 5.1.1 Final. But It's not working. The same code works in my JUNIT but not in the web application. </p>
  
  <p>The code which works:</p>
  
  <pre><code>@Test
      public void testUserAuthenticationRequestValidation(){
          try{
          UserAuthenticationRequest req=new UserAuthenticationRequest().addUserName("bla").addPasswd("passw");
          Validator validation=Validation.buildDefaultValidatorFactory().getValidator();
          Set&lt;ConstraintViolation&lt;UserAuthenticationRequest&gt;&gt; constraintViolations= validation.validate(req);
          Assert.assertTrue("There are some errors", constraintViolations.size()&gt;0);
          System.out.println(constraintViolations);
          }catch(Exception ex){
              ex.printStackTrace();
              Assert.fail();
          }
  </code></pre>
  
  <p>But if I try to use the same code in my web application, it doesn't work, In the below code, I am expecting contraintViolation set not to be empty because I intentionally left both the username &amp; password empty but I always find it empty. </p>
  
  <pre><code>@Override
      public UserDetails retrieveUser(String username,
              UsernamePasswordAuthenticationToken authentication)
              throws AuthenticationException {
          LOGGER.debug("About to check authentication for username: {}", username);
          final UserAuthenticationRequest userData = new UserAuthenticationRequest()
                  .addUserName(username).addPasswd(
                          authentication.getCredentials().toString());
          Validator validation = Validation.buildDefaultValidatorFactory()
                  .getValidator();
          Set&lt;ConstraintViolation&lt;UserAuthenticationRequest&gt;&gt; constraintViolations = validation
                  .validate(userData);
          LOGGER.info("Constraints Violations: {}", constraintViolations);
          LOGGER.info("Obejct: username: {} password: {}",
                  userData.getUsername(), userData.getPasswd());
          UserDetailVO userDetailVO = new UserDetailVO(
                  userInfoService.authenticate(userData));
          return userDetailVO;
      }
  </code></pre>
  
  <p>So far I have also tried in vain initializing the validation bean as shown below and injecting in my Class as well as shown below:</p>
  
  <pre><code>@Configuration
  @ComponentScan({ "com.sell.mystuff.web.security",
          "com.sell.mystuff.web.service" })
  @ImportResource({ "classpath*:spring/common-context.xml" })
  public class CommonAppContext {
  
      @Bean(name = "javaxValidator")
      public Validator getValidator() {
          return Validation.buildDefaultValidatorFactory().getValidator();
      }
  
  }
  </code></pre>
  
  <p>I have even tried to explicitly initialized in the validation bean as shown above but nothing seems to be working. 
  Below is my partial POM.xml file related to validation api:</p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;5.1.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.el&lt;/groupId&gt;
          &lt;artifactId&gt;javax.el-api&lt;/artifactId&gt;
          &lt;version&gt;2.2.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.web&lt;/groupId&gt;
          &lt;artifactId&gt;javax.el&lt;/artifactId&gt;
          &lt;version&gt;2.2.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator-annotation-processor&lt;/artifactId&gt;
          &lt;version&gt;5.1.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>