title: Bean validation with Spring and Hibernate doesn't work
body: <p>I'm trying to validate this bean:</p>
  
  <pre><code>public class NewUserCompanyForm implements Serializable {
  private static final long serialVersionUID = 6414340627544822204L;
  
  @Email(groups = ValidationGroup1.class)
  @NotBlank(groups = ValidationGroup1.class)
  @Length(min = 5)
  private String userName;
  
  @NotBlank(groups = ValidationGroup1.class)
  private String password;
  
  @NotBlank(groups = ValidationGroup1.class)
  private String repeatedPassword;
  
  @NotBlank(groups = ValidationGroup2.class)
  private String companyName;
  
  @Pattern(regexp = "\\d\\d-\\d\\d\\d", groups = ValidationGroup2.class)
  private String postalCode;
  
  @NotBlank(groups = ValidationGroup2.class)
  @Pattern(regexp = "\\p{L}*", groups = ValidationGroup2.class)
  private String city;
  
  @Pattern(regexp = "[-A-Za-z0-9 ,.]*", groups = ValidationGroup2.class)
  @NotBlank(groups = ValidationGroup2.class)
  private String addressDetails;
  </code></pre>
  
  <p>Unfortunately I'm getting exceptions for almost all field validations:</p>
  
  <pre><code>javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.Email' validating type 'java.lang.String'. Check configuration for 'userName'
  </code></pre>
  
  <p>It is always <code>UnexpectedTypeException: HV000030</code>. I read the documentation of Hibernate and Spring validation and everything seems to be OK, since e.g. <code>@Email</code> annotation can be used with Strings.</p>
  
  <p>EDIT: added pom.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;thymeleaf.spring.version&gt;3.0.7.RC1&lt;/thymeleaf.spring.version&gt;
      &lt;thymeleaf.version&gt;3.0.7.RELEASE&lt;/thymeleaf.version&gt;
      &lt;hibernate.validation.version&gt;6.0.2.Final&lt;/hibernate.validation.version&gt;
      &lt;hibernate.version&gt;5.2.11.Final&lt;/hibernate.version&gt;
      &lt;hibernate.commons.version&gt;5.0.1.Final&lt;/hibernate.commons.version&gt;
      &lt;bean.validation.api.version&gt;2.0.0.Final&lt;/bean.validation.api.version&gt;
      &lt;mysql.connector.java.version&gt;6.0.6&lt;/mysql.connector.java.version&gt;
      &lt;spring.version&gt;5.0.0.RELEASE&lt;/spring.version&gt;
      &lt;spring.session.version&gt;1.3.1.RELEASE&lt;/spring.session.version&gt;
      &lt;spring.security.version&gt;4.2.3.RELEASE&lt;/spring.security.version&gt;
      &lt;spring.webflow.version&gt;2.4.6.RELEASE&lt;/spring.webflow.version&gt;
      &lt;spring.boot.test.version&gt;2.0.0.M5&lt;/spring.boot.test.version&gt;
      &lt;common.codecs&gt;1.10&lt;/common.codecs&gt;
  &lt;/properties&gt;
  
  &lt;groupId&gt;pwr.groupproject.vouchers&lt;/groupId&gt;
  &lt;artifactId&gt;voucherApp&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.7.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
          &lt;artifactId&gt;spring-session-jdbc&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
          &lt;artifactId&gt;spring-session&lt;/artifactId&gt;
          &lt;version&gt;${spring.session.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring5 --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf-spring5&lt;/artifactId&gt;
          &lt;version&gt;${thymeleaf.spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.validator&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.validation.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/javax.validation/validation-api --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;${bean.validation.api.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;${mysql.connector.java.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf&lt;/artifactId&gt;
          &lt;version&gt;${thymeleaf.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-context --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
          &lt;version&gt;${spring.security.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.common&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.commons.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-codec&lt;/groupId&gt;
          &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
          &lt;version&gt;${common.codecs}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webflow&lt;/artifactId&gt;
          &lt;version&gt;${spring.webflow.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;repositories&gt;
  &lt;/repositories&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the class being used to test the validation:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {SpringWebFlowConfiguration.class, WebConfiguration.class})
  public class NewUserCompanyFormValidationTest {
      @Autowired
      @Qualifier("localValidatorFactoryBean")
      private LocalValidatorFactoryBean validator;
      @Autowired
      private MessageSource messageSource;
  
      @Test
      public void DependencyInjectionTest(){
          Assert.assertNotNull(validator);
      }
  
      @Test
      public void NewUserCompanyFormValidatingTest(){
          NewUserCompanyForm form1=new NewUserCompanyForm();
          form1.setPassword("");
          form1.setUserName("");
          form1.setRepeatedPassword("");
          Set&lt;ConstraintViolation&lt;NewUserCompanyForm&gt;&gt; volations1=validator.validate(form1,NewUserCompanyForm.ValidationGroup1.class);
  
      }
  }
  </code></pre>