Spring迁移2.0.2到2.1.4 Hibernate验证器错误

问题描述 投票:1回答:1

我正在尝试将我的spring-boot Web应用程序从v 2.0.2迁移到2.1.4但是当我尝试使用验证器找到一个元素时,我遇到了问题,hibernate抛出异常

HV000243: Constraint 
validators.annotations.StringaData references constraint validator type 
validators.impl.DateValidator, but this validator is defined for constraint type 
validators.annotations.StringaData.

这里是SpringData.java

@Target({ElementType.FIELD })
@Retention(RUNTIME)
@Constraint(validatedBy = DateValidator.class)
public @interface StringaData {

      String message() default MessagesKeys.MUST_BE_DATE;

      Class<?>[] groups() default {};

      Class<? extends Payload>[] payload() default {};
}

和DateValidator.java

public class DateValidator implements ConstraintValidator<StringaData, String> {

    @Override
    public boolean isValid(String str, ConstraintValidatorContext context) {
        if( str != null && ValidationUtilsCustom.isNotEmptyOrWhitespace(str))
            return ValidationUtilsCustom.isStringDate(str);
        return true;
    }
}

我在这里阅读了文档https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-customconstraints-constraintannotation

这里我的课程应用了验证器

public class elementDTO implements Serializable {

    private BigDecimal Id; // Id or Primary Key

    @StringaData
    private String dataStr;
    @StringaData
    private String field2Str;

    //getter and setter

}

我究竟做错了什么?

以下是我的Web应用程序中的完整依赖项列表

    [INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.4.RELEASE:compile
    [INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.8:compile
    [INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.8:compile
    [INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.8:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework:spring-web:jar:5.1.6.RELEASE:compile
    [INFO] |  |  \- org.springframework:spring-beans:jar:5.1.6.RELEASE:compile
    [INFO] |  +- org.glassfish.jersey.core:jersey-server:jar:2.27:compile
    [INFO] |  |  +- org.glassfish.jersey.core:jersey-common:jar:2.27:compile
    [INFO] |  |  |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
    [INFO] |  |  +- org.glassfish.jersey.core:jersey-client:jar:2.27:compile
    [INFO] |  |  +- javax.ws.rs:javax.ws.rs-api:jar:2.1:compile
    [INFO] |  |  +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.27:compile
    [INFO] |  |  \- javax.validation:validation-api:jar:2.0.1.Final:compile
    [INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.27:compile
    [INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.27:compile
    [INFO] |  +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.27:compile
    [INFO] |  +- org.glassfish.jersey.ext:jersey-spring4:jar:2.27:compile
    [INFO] |  |  +- org.glassfish.jersey.inject:jersey-hk2:jar:2.27:compile
    [INFO] |  |  |  \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b42:compile
    [INFO] |  |  |     \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42:compile
    [INFO] |  |  +- org.glassfish.hk2:hk2:jar:2.5.0-b42:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b42:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-api:jar:2.5.0-b42:compile
    [INFO] |  |  |  +- org.glassfish.hk2:config-types:jar:2.5.0-b42:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-core:jar:2.5.0-b42:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-config:jar:2.5.0-b42:compile
    [INFO] |  |  |  +- org.glassfish.hk2:hk2-runlevel:jar:2.5.0-b42:compile
    [INFO] |  |  |  \- org.glassfish.hk2:class-model:jar:2.5.0-b42:compile
    [INFO] |  |  |     \- org.glassfish.hk2.external:asm-all-repackaged:jar:2.5.0-b42:compile
    [INFO] |  |  +- org.glassfish.hk2:spring-bridge:jar:2.5.0-b42:compile
    [INFO] |  |  \- org.springframework:spring-aop:jar:5.1.6.RELEASE:compile
    [INFO] |  +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.27:compile
    [INFO] |  |  \- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.27:compile
    [INFO] |  \- javax.xml.bind:jaxb-api:jar:2.3.1:compile
    [INFO] |     \- javax.activation:javax.activation-api:jar:1.2.0:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.4.RELEASE:provided
    [INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
    [INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.17:provided
    [INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.17:compile
    [INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.17:provided
    [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.4.RELEASE:test
    [INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.4.RELEASE:test
    [INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.4.RELEASE:test
    [INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
    [INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
    [INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
    [INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
    [INFO] |  +- org.mockito:mockito-core:jar:2.23.4:test
    [INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.12:compile
    [INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.12:test
    [INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
    [INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
    [INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
    [INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
    [INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
    [INFO] |  +- org.springframework:spring-core:jar:5.1.6.RELEASE:compile
    [INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.6.RELEASE:compile
    [INFO] |  +- org.springframework:spring-test:jar:5.1.6.RELEASE:test
    [INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.2:test
    [INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.1.4.RELEASE:compile
    [INFO] |  |  +- org.springframework.boot:spring-boot-actuator:jar:2.1.4.RELEASE:compile
    [INFO] |  |  \- org.springframework:spring-context:jar:5.1.6.RELEASE:compile
    [INFO] |  \- io.micrometer:micrometer-core:jar:1.1.4:compile
    [INFO] |     +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
    [INFO] |     \- org.latencyutils:LatencyUtils:jar:2.0.3:compile
    [INFO] +- org.springframework.boot:spring-boot-starter:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.4.RELEASE:compile
    [INFO] |  \- org.yaml:snakeyaml:jar:1.23:runtime
    [INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.2:compile
    [INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
    [INFO] |  +- org.apache.logging.log4j:log4j-jul:jar:2.11.2:compile
    [INFO] |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
    [INFO] +- org.apache.logging.log4j:log4j-web:jar:2.11.2:compile
    [INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.16.Final:compile
    [INFO] |  |  \- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
    [INFO] |  \- org.springframework:spring-webmvc:jar:5.1.6.RELEASE:compile
    [INFO] |     \- org.springframework:spring-expression:jar:5.1.6.RELEASE:compile
    [INFO] +- commons-lang:commons-lang:jar:2.6:compile
    [INFO] +- org.springframework.cloud:spring-cloud-starter-netflix-hystrix:jar:2.1.1.RELEASE:compile
    [INFO] |  +- org.springframework.cloud:spring-cloud-starter:jar:2.1.1.RELEASE:compile
    [INFO] |  |  +- org.springframework.cloud:spring-cloud-context:jar:2.1.1.RELEASE:compile
    [INFO] |  |  |  \- org.springframework.security:spring-security-crypto:jar:5.1.5.RELEASE:compile
    [INFO] |  |  +- org.springframework.cloud:spring-cloud-commons:jar:2.1.1.RELEASE:compile
    [INFO] |  |  \- org.springframework.security:spring-security-rsa:jar:1.0.7.RELEASE:compile
    [INFO] |  |     \- org.bouncycastle:bcpkix-jdk15on:jar:1.60:compile
    [INFO] |  |        \- org.bouncycastle:bcprov-jdk15on:jar:1.60:compile
    [INFO] |  +- org.springframework.cloud:spring-cloud-netflix-hystrix:jar:2.1.1.RELEASE:compile
    [INFO] |  +- org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.1.1.RELEASE:compile
    [INFO] |  |  \- org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.1.1.RELEASE:compile
    [INFO] |  +- org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar:2.1.1.RELEASE:compile
    [INFO] |  |  +- com.netflix.archaius:archaius-core:jar:0.7.6:compile
    [INFO] |  |  \- commons-configuration:commons-configuration:jar:1.8:compile
    [INFO] |  +- com.netflix.hystrix:hystrix-core:jar:1.5.18:compile
    [INFO] |  |  \- io.reactivex:rxjava:jar:1.3.8:compile
    [INFO] |  +- com.netflix.hystrix:hystrix-serialization:jar:1.5.18:compile
    [INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.9.8:runtime
    [INFO] |  +- com.netflix.hystrix:hystrix-metrics-event-stream:jar:1.5.18:compile
    [INFO] |  +- com.netflix.hystrix:hystrix-javanica:jar:1.5.18:compile
    [INFO] |  |  +- org.ow2.asm:asm:jar:5.0.4:runtime
    [INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.9.2:compile
    [INFO] |  \- io.reactivex:rxjava-reactive-streams:jar:1.2.1:compile
    [INFO] |     \- org.reactivestreams:reactive-streams:jar:1.0.2:runtime
    [INFO] +- org.springframework.cloud:spring-cloud-starter-zipkin:jar:2.1.1.RELEASE:compile
    [INFO] |  +- org.springframework.cloud:spring-cloud-starter-sleuth:jar:2.1.1.RELEASE:compile
    [INFO] |  |  \- org.springframework.cloud:spring-cloud-sleuth-core:jar:2.1.1.RELEASE:compile
    [INFO] |  |     +- org.aspectj:aspectjrt:jar:1.9.2:compile
    [INFO] |  |     +- io.zipkin.brave:brave:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-context-log4j2:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-instrumentation-spring-web:jar:5.6.1:compile
    [INFO] |  |     |  \- io.zipkin.brave:brave-instrumentation-http:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-instrumentation-spring-rabbit:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-instrumentation-kafka-clients:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-instrumentation-httpclient:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-instrumentation-httpasyncclient:jar:5.6.1:compile
    [INFO] |  |     +- io.zipkin.brave:brave-instrumentation-spring-webmvc:jar:5.6.1:compile
    [INFO] |  |     |  \- io.zipkin.brave:brave-instrumentation-servlet:jar:5.6.1:compile
    [INFO] |  |     \- io.zipkin.brave:brave-instrumentation-jms:jar:5.6.1:compile
    [INFO] |  \- org.springframework.cloud:spring-cloud-sleuth-zipkin:jar:2.1.1.RELEASE:compile
    [INFO] |     +- io.zipkin.zipkin2:zipkin:jar:2.12.0:compile
    [INFO] |     +- io.zipkin.reporter2:zipkin-reporter:jar:2.7.14:compile
    [INFO] |     +- io.zipkin.reporter2:zipkin-sender-kafka11:jar:2.7.14:compile
    [INFO] |     \- io.zipkin.reporter2:zipkin-sender-amqp-client:jar:2.7.14:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.1.4.RELEASE:compile
    [INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.1.4.RELEASE:compile
    [INFO] |  |  +- com.zaxxer:HikariCP:jar:3.2.0:compile
    [INFO] |  |  \- org.springframework:spring-jdbc:jar:5.1.6.RELEASE:compile
    [INFO] |  +- javax.transaction:javax.transaction-api:jar:1.3:compile
    [INFO] |  +- org.hibernate:hibernate-core:jar:5.3.9.Final:compile
    [INFO] |  |  +- javax.persistence:javax.persistence-api:jar:2.2:compile
    [INFO] |  |  +- org.javassist:javassist:jar:3.23.1-GA:compile
    [INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
    [INFO] |  |  +- org.jboss:jandex:jar:2.0.5.Final:compile
    [INFO] |  |  +- org.dom4j:dom4j:jar:2.1.1:compile
    [INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
    [INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.1.6.RELEASE:compile
    [INFO] |  |  +- org.springframework.data:spring-data-commons:jar:2.1.6.RELEASE:compile
    [INFO] |  |  +- org.springframework:spring-orm:jar:5.1.6.RELEASE:compile
    [INFO] |  |  \- org.springframework:spring-tx:jar:5.1.6.RELEASE:compile
    [INFO] |  \- org.springframework:spring-aspects:jar:5.1.6.RELEASE:compile
    [INFO] +- com.github.noraui:ojdbc7:jar:12.1.0.2:compile
    [INFO] +- com.querydsl:querydsl-apt:jar:4.2.1:compile
    [INFO] |  \- com.querydsl:querydsl-codegen:jar:4.2.1:compile
    [INFO] |     +- com.mysema.codegen:codegen:jar:0.6.8:compile
    [INFO] |     |  \- org.eclipse.jdt.core.compiler:ecj:jar:4.3.1:compile
    [INFO] |     \- org.reflections:reflections:jar:0.9.9:compile
    [INFO] |        \- com.google.code.findbugs:annotations:jar:2.0.1:compile
    [INFO] +- com.querydsl:querydsl-jpa:jar:4.2.1:compile
    [INFO] |  +- com.querydsl:querydsl-core:jar:4.2.1:compile
    [INFO] |  |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
    [INFO] |  |  +- com.mysema.commons:mysema-commons-lang:jar:0.2.4:compile
    [INFO] |  |  \- com.infradna.tool:bridge-method-annotation:jar:1.13:compile
    [INFO] |  +- javax.inject:javax.inject:jar:1:compile
    [INFO] |  \- org.slf4j:slf4j-api:jar:1.7.26:compile
    [INFO] +- org.springframework.boot:spring-boot-starter-web-services:jar:2.1.4.RELEASE:compile
    [INFO] |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.5.0:compile
    [INFO] |  |  +- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
    [INFO] |  |  +- org.jvnet.mimepull:mimepull:jar:1.9.11:compile
    [INFO] |  |  \- org.jvnet.staxex:stax-ex:jar:1.8:compile
    [INFO] |  +- javax.xml.ws:jaxws-api:jar:2.3.1:compile
    [INFO] |  +- org.springframework:spring-oxm:jar:5.1.6.RELEASE:compile
    [INFO] |  \- org.springframework.ws:spring-ws-core:jar:3.0.7.RELEASE:compile
    [INFO] |     +- org.springframework.ws:spring-xml:jar:3.0.7.RELEASE:compile
    [INFO] |     \- commons-io:commons-io:jar:2.5:compile
    [INFO] +- org.modelmapper.extensions:modelmapper-spring:jar:1.1.0:compile
    [INFO] |  \- org.modelmapper:modelmapper:jar:1.1.0:compile
    [INFO] +- io.springfox:springfox-swagger2:jar:2.6.1:compile
    [INFO] |  +- io.swagger:swagger-annotations:jar:1.5.10:compile
    [INFO] |  +- io.swagger:swagger-models:jar:1.5.10:compile
    [INFO] |  +- io.springfox:springfox-spi:jar:2.6.1:compile
    [INFO] |  |  \- io.springfox:springfox-core:jar:2.6.1:compile
    [INFO] |  +- io.springfox:springfox-schema:jar:2.6.1:compile
    [INFO] |  +- io.springfox:springfox-swagger-common:jar:2.6.1:compile
    [INFO] |  +- io.springfox:springfox-spring-web:jar:2.6.1:compile
    [INFO] |  +- com.google.guava:guava:jar:18.0:compile
    [INFO] |  +- com.fasterxml:classmate:jar:1.4.0:compile
    [INFO] |  +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
    [INFO] |  +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
    [INFO] |  \- org.mapstruct:mapstruct:jar:1.0.0.Final:compile
    [INFO] +- io.springfox:springfox-swagger-ui:jar:2.6.1:compile
    [INFO] +- org.apache.maven:maven-model:jar:3.3.9:compile
    [INFO] |  +- org.codehaus.plexus:plexus-utils:jar:3.0.22:compile
    [INFO] |  \- org.apache.commons:commons-lang3:jar:3.8.1:compile
    [INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:2.1.4.RELEASE:compile
    [INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.9.8:compile
    [INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
    [INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
    [INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.8:compile
    [INFO] |  +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.8:compile
    [INFO] |  +- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
    [INFO] |  \- com.fasterxml.woodstox:woodstox-core:jar:5.0.3:compile
    [INFO] \- junit:junit:jar:4.12:test
java spring hibernate hibernate-validator
1个回答
2
投票

哼。这真的很奇怪。

你确定你的类路径中没有2个不同的StringaData实现吗?因为它看起来确实有2个不同的类具有相同的名称,并且会产生混淆。

它也可能是一个类加载器问题,但通常情况下,在典型的Spring安装程序中没有这些问题。

© www.soinside.com 2019 - 2024. All rights reserved.