Spring boot 带有未知@PastOrPresent注释的Spring boot应用程序

Spring boot 带有未知@PastOrPresent注释的Spring boot应用程序,spring-boot,bean-validation,Spring Boot,Bean Validation,在spring boot web应用程序中, 当我使用@PastOrPresent STS时,会显示以下错误: 无法将当前文件解析为类型 但是org.springframework.boot:springbootstarter验证条目已经在依赖项中 梯度锉 buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { mavenCentral() }

在spring boot web应用程序中, 当我使用@PastOrPresent STS时,会显示以下错误:

无法将当前文件解析为类型

但是org.springframework.boot:springbootstarter验证条目已经在依赖项中

梯度锉

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')
}
Gradle文件的更新

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')
}

我还有别的事要做吗?在实体内部,我仍然有相同的错误。新版本:NotEmpty类型已被弃用,如doc所示。

问题在于@PastOrPresent约束是Bean Validation 2.0的一部分,而Spring引导默认情况下仍使用Hibernate Validator 5.3。请参见依赖项,即BeanValidation 1.1。如果你想使用这个新的约束,你需要对Hibernate Validator 6.0有一个明确的依赖项,并从当前的依赖项中排除5.4版本。

Thx,请参阅原始消息更新,我想我必须添加显式编译“javax.validation:validation api:2.0.1.Final”,当它被org.hibernate.validator:hibernate validator:6.0.7.final节点下的1.1.0.final版本所取代时,是的,看起来是这样。至于弃用警告。这是意料之中的@NotEmpty被添加到Bean Validation 2.0中,因此Hibernate Validator中的版本被弃用,取而代之的是规范中的版本。只需使用javax.Validation.constraints中的版本即可