首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有unkown @PastOrPresent注释的Spring引导应用程序

带有unkown @PastOrPresent注释的Spring引导应用程序
EN

Stack Overflow用户
提问于 2018-01-23 17:55:19
回答 1查看 1.8K关注 0票数 0

在spring web-app中,当我使用@PastOrPresent时,显示了以下错误:

(无法将PastOrPresent解析为类型)

但是org.springframework.boot:spring-boot-starter-validation条目已经是依赖项之一了。

分级文件

代码语言:javascript
复制
buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.domain'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"

repositories {
    mavenCentral()
}


dependencies {

    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-actuator-docs')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-validation')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('org.postgresql:postgresql')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
}

分级文件更新

代码语言:javascript
复制
...

compile('org.springframework.boot:spring-boot-starter-validation'){
 exclude group: 'org.hibernate', module: 'hibernate-validator:5.3.6.Final'
}
compile 'org.hibernate:hibernate-validator:6.0.7.Final'

...

|    \--- org.hibernate:hibernate-validator:5.3.6.Final -> 6.0.7.Final
|         \--- org.hibernate.validator:hibernate-validator:6.0.7.Final
|              +--- javax.validation:validation-api:2.0.1.Final -> 1.1.0.Final
|              +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.1.Final
|              \--- com.fasterxml:classmate:1.3.1 -> 1.3.4

我还有别的事要做吗?在实体内部,我仍然有相同的错误。使用新的:不推荐使用NotEmpty类型(如doc 这里所示)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-23 18:01:01

问题是,@PastOrPresent约束是BeanValidation2.0(参见这里)的一部分,而Spring默认情况下仍然使用Hibernate Validator 5.3 (参见依赖项这里),即BeanValidation 1.1。如果您想使用这个新约束,则需要对Hibernate Validator 6.0具有显式依赖关系,并将5.4版本排除在当前依赖项之外。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48407999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档