tomcat 上缺少验证器
Posted
技术标签:
【中文标题】tomcat 上缺少验证器【英文标题】:Missing Validators on tomcat 【发布时间】:2021-07-08 20:04:53 【问题描述】:我正在尝试将休眠验证器与 SpringBoot 和 Tomcat 一起使用,但仍然出现此错误
No validator could be found for constraint 'javax.validation.constraints.NotBlank'
我尝试将以下内容添加到我的 maven pom.xml 中,但没有运气
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<version>4.0.0-RC2</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>7.0.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
它在由 java 启动时在本地工作,那么我该如何解决这个问题?我发现了这个问题[HV000030: No validator could be found for constraint 'javax.validation.constraints.NotEmpty' validating type 'java.lang.String',但当我仔细检查 hibernate-validator 的版本为 7 时,它似乎并没有解决我的问题。
文件引起的问题可以在这里看到https://github.com/OntoloBridge/ontolobridge-project/blob/Authentication/src/main/java/edu/miami/schurer/ontolobridge/models/User.java
这是我的依赖树
[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @
ontologbridge ---
[INFO] edu.miami.schurer:ontologbridge:war:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.0.5.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:5.0.9.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.5.RELEASE:compile
[INFO] | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] | | | \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] | | \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] | +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] | +- org.springframework:spring-core:jar:5.0.9.RELEASE:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.0.9.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.0.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.0.5.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-actuator:jar:2.0.5.RELEASE:compile
[INFO] | | \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.6:compile
[INFO] | \- io.micrometer:micrometer-core:jar:1.0.6:compile
[INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.10:compile
[INFO] | \- org.latencyutils:LatencyUtils:jar:2.0.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.0.5.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.6:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.6:compile
[INFO] | +- org.springframework:spring-web:jar:5.0.9.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.0.9.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.0.9.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.0.9.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:2.0.5.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.0.9.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:5.0.8.RELEASE:compile
[INFO] | | \- org.springframework.security:spring-security-core:jar:5.0.8.RELEASE:compile
[INFO] | \- org.springframework.security:spring-security-web:jar:5.0.8.RELEASE:compile
[INFO] +- org.postgresql:postgresql:jar:42.2.5:runtime
[INFO] +- io.jsonwebtoken:jjwt:jar:0.9.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] +- mysql:mysql-connector-java:jar:8.0.20:compile
[INFO] | \- com.google.protobuf:protobuf-java:jar:3.6.1:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.1.1:compile
[INFO] | \- org.apache.commons:commons-pool2:jar:2.5.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.5.RELEASE:provided
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.34:provided
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.34:provided
[INFO] | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.34:provided
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.5.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:2.0.5.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.5.RELEASE:test
[INFO] | +- junit:junit:jar:4.12:test
[INFO] | +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] | +- org.mockito:mockito-core:jar:2.15.0:test
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.7.11:compile
[INFO] | | +- net.bytebuddy:byte-buddy-agent:jar:1.7.11: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-test:jar:5.0.9.RELEASE:test
[INFO] | \- org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.5.RELEASE:compile
[INFO] | +- com.zaxxer:HikariCP:jar:2.7.9:compile
[INFO] | \- org.springframework:spring-jdbc:jar:5.0.9.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:5.0.9.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:2.0.5.RELEASE:compile (optional)
[INFO] +- it.ozimov:spring-boot-email-core:jar:0.6.3:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-mail:jar:2.0.5.RELEASE:compile
[INFO] | | +- org.springframework:spring-context-support:jar:5.0.9.RELEASE:compile
[INFO] | | \- com.sun.mail:javax.mail:jar:1.6.2:compile
[INFO] | | \- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.apache.tika:tika-core:jar:1.14:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.3.3.Final:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.0.5.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-redis:jar:2.0.10.RELEASE:compile
[INFO] | | | +- org.springframework.data:spring-data-keyvalue:jar:2.0.10.RELEASE:compile
[INFO] | | | \- org.springframework:spring-oxm:jar:5.0.9.RELEASE:compile
[INFO] | | \- io.lettuce:lettuce-core:jar:5.0.5.RELEASE:compile
[INFO] | | +- io.projectreactor:reactor-core:jar:3.1.9.RELEASE:compile
[INFO] | | | \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.29.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.29.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.29.Final:compile
[INFO] | | | \- io.netty:netty-resolver:jar:4.1.29.Final:compile
[INFO] | | \- io.netty:netty-handler:jar:4.1.29.Final:compile
[INFO] | | \- io.netty:netty-codec:jar:4.1.29.Final:compile
[INFO] | +- it.ozimov:embedded-redis:jar:0.7.0:compile
[INFO] | | \- commons-io:commons-io:jar:2.5:compile
[INFO] | +- org.owasp.encoder:encoder:jar:1.2.1:compile
[INFO] | \- com.google.guava:guava:jar:21.0:compile
[INFO] +- com.opencsv:opencsv:jar:4.1:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] | +- org.apache.commons:commons-text:jar:1.1:compile
[INFO] | \- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | \- commons-collections:commons-collections:jar:3.2.2:compile
[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.ow2.asm:asm:jar:5.0.4:test
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.9.2:compile
[INFO] | +- io.swagger:swagger-annotations:jar:1.5.20:compile
[INFO] | +- io.swagger:swagger-models:jar:1.5.20:compile
[INFO] | +- io.springfox:springfox-spi:jar:2.9.2:compile
[INFO] | | \- io.springfox:springfox-core:jar:2.9.2:compile
[INFO] | +- io.springfox:springfox-schema:jar:2.9.2:compile
[INFO] | +- io.springfox:springfox-swagger-common:jar:2.9.2:compile
[INFO] | +- io.springfox:springfox-spring-web:jar:2.9.2:compile
[INFO] | +- com.fasterxml:classmate:jar:1.3.4: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.2.0.Final:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:2.9.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.0.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:2.0.5.RELEASE:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +- org.hibernate:hibernate-core:jar:5.2.17.Final:compile
[INFO] | | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.2.Final:compile
[INFO] | | +- org.javassist:javassist:jar:3.22.0-GA:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:2.0.10.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:2.0.10.RELEASE:compile
[INFO] | | \- org.springframework:spring-orm:jar:5.0.9.RELEASE:compile
[INFO] | \- org.springframework:spring-aspects:jar:5.0.9.RELEASE:compile
[INFO] +- io.sentry:sentry:jar:1.7.30:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] +- io.sentry:sentry-logback:jar:1.7.30:compile
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | \- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] | \- jakarta.activation:jakarta.activation-api:jar:1.2.1:compile
[INFO] +- org.glassfish.jaxb:jaxb-runtime:jar:2.3.2:compile
[INFO] | +- org.glassfish.jaxb:txw2:jar:2.3.2:compile
[INFO] | +- com.sun.istack:istack-commons-runtime:jar:3.0.8:compile
[INFO] | +- org.jvnet.staxex:stax-ex:jar:1.8.1:compile
[INFO] | \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.16:compile
[INFO] +- org.hibernate.validator:hibernate-validator:jar:7.0.1.Final:compile
[INFO] | +- jakarta.validation:jakarta.validation-api:jar:3.0.0:compile
[INFO] | \- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] +- org.glassfish:jakarta.el:jar:4.0.0-RC2:compile
[INFO] | \- jakarta.el:jakarta.el-api:jar:4.0.0-RC2:compile
[INFO] +- org.hibernate.validator:hibernate-validator-cdi:jar:7.0.1.Final:compile
[INFO] \- javax.validation:validation-api:jar:2.0.1.Final:compile
【问题讨论】:
Hibernate 验证器 7 是一个 jakarta 验证 api 实现。您需要版本 6 而不是 7。Spring (Boot) 不支持 JakartaEE。 【参考方案1】:问题似乎是 spring-boot-email-core
[INFO] +- it.ozimov:spring-boot-email-core:jar:0.6.3:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.3.3.Final:compile
将以下内容添加到依赖项修复它
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
【讨论】:
以上是关于tomcat 上缺少验证器的主要内容,如果未能解决你的问题,请参考以下文章
在 Tomcat 上使用 Spring Boot 进行身份验证
FBWebDialogs 缺少用于验证用户的会话 Cookie