Autowired 和 Validated 之间的冲突

我一直在寻找几天,与可能发生的冲突或我在将 spring 引导放入项目时所做的错误配置相关的问题。


当代码中不存在 (@Validated) 时,所有依赖项通常都会被注入 (@Autowired),因此它被插入,一切都停止被 spring 注入。


gradle.properties


SPRING_BOOT_VERSION=2.0.3.RELEASE

SPRING_CLOUD_VERSION=Finchley.RELEASE

我试过这个版本:


SPRING_BOOT_VERSION=2.1.0.M2

依赖 build.gradle


buildscript {

    ext {

        springBootVersion = SPRING_BOOT_VERSION

        springCloudVersion = SPRING_CLOUD_VERSION

    }

    repositories {

        jcenter()

        mavenLocal()

        mavenCentral()

        maven { url 'https://plugins.gradle.org/m2/' }

        maven { url "https://repo.spring.io/snapshot" }

        maven { url "https://repo.spring.io/milestone" }

    }

    dependencies {

        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}",

            "org.owasp:dependency-check-gradle:3.2.1"

    }

}


dependencies {


    compile "org.springframework.boot:spring-boot-starter-actuator",

        "org.springframework.boot:spring-boot-starter-webflux",

        "org.springframework.boot:spring-boot-starter-validation",

        "org.springframework.boot:spring-boot-starter-logging",

        "org.springframework.boot:spring-boot-starter-jetty",

        "org.springframework.boot:spring-boot-starter-cache",

        "org.springframework.boot:spring-boot-starter-jdbc",

        "org.springframework.boot:spring-boot-starter-web",

        "org.springframework.boot:spring-boot-starter-aop",

        "org.springframework:spring-context",

        "io.springfox:springfox-swagger2:2.9.0",

        "io.springfox:springfox-swagger-ui:2.9.0"


    compile "org.eclipse.jetty:jetty-alpn-conscrypt-server",

        "org.eclipse.jetty.http2:http2-server",

        "org.owasp:dependency-check-gradle:3.2.1",

        "org.codehaus.groovy:groovy-all:2.4.15",

        "org.liquibase:liquibase-core:3.6.1"


    compileOnly "org.projectlombok:lombok:1.18.0"


    runtime "mysql:mysql-connector-java:5.1.34"

}


largeQ
浏览 211回答 1
1回答

郎朗坤

我明白,通过定义一个方法final,类设计者承诺这个方法将始终如描述或暗示的那样工作。但是验证需要创建部分自定义,只有在没有最终.变化自:public final ResponseEntity<Response> createUser(@RequestHeader("token") final String token, @RequestBody final Request request) {&nbsp; &nbsp; return createUser.execute( ... ); // createUser is null}为了public ResponseEntity<Response> createUser(@RequestHeader("token") final String token, @RequestBody final Request request) {&nbsp; &nbsp; return createUser.execute( ... ); // createUser is null}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java