解决Springfox报错:"this.condition" is null的问题

728 阅读1分钟

摘要:当集成Swagger时,如果你遇到了类似于"this.condition" is null的错误信息,这意味着Swagger与你当前使用的Spring Boot版本不兼容。本文将介绍如何解决这个问题,通过将Spring Boot版本降低到2.5.2来实现。


在使用Springfox和Swagger集成时,你可能会遇到以下错误信息:

Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null

这个错误的原因是Swagger与当前的Spring Boot版本不兼容。为了解决这个问题,你可以按照以下步骤将Spring Boot版本降低到2.5.2。

  1. 打开你的项目配置文件(通常是build.gradle文件)。
  2. plugins部分找到org.springframework.boot插件,并将其版本更改为2.5.2。确保你的配置文件类似于下面的代码片段:
groovyCopy code
plugins {
    id 'java'
    id 'org.springframework.boot' version '2.5.2'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

// 其他配置...

dependencies {
    // 其他依赖...
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'io.springfox:springfox-boot-starter:3.0.0'
}

// 其他任务...

我使用的是gradle构建的项目,如果你用的是maven同理修改pom.xml降低springboot版本即可

  1. 保存并关闭配置文件。

通过以上步骤,你已经将Spring Boot版本降低到2.5.2,解决了Swagger与Spring Boot不兼容的问题。重新构建和运行你的应用程序,应该不再遇到上述报错信息。

希望本文对你解决Springfox报错问题有所帮助。如果你还有其他问题或疑问,请随时在下方留言。感谢阅读!