Spring Boot v2.2.2.RELEASE项目适配Swagger版本咨询
Hey there! For your Spring Boot v2.2.2.RELEASE application, the springfox-swagger2 and springfox-swagger-ui versions you should use are 2.9.2.
Why this version?
This release of springfox is specifically built to work smoothly with Spring Boot 2.x versions (including the 2.2.x series). Later springfox versions (like 3.0.0 and above) raised the minimum Spring Boot requirement to 2.3.x and higher, which makes them incompatible with your v2.2.2.RELEASE setup.
Example Maven Dependencies
Add these to your pom.xml:
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
Gradle Equivalent
If you're using Gradle, add these to your build.gradle:
implementation 'io.springfox:springfox-swagger2:2.9.2' implementation 'io.springfox:springfox-swagger-ui:2.9.2'
Quick Configuration Tip
You'll also need a basic configuration class to enable Swagger:
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("your.package.name")) .paths(PathSelectors.any()) .build(); } }
Once set up, you can access the Swagger UI at http://localhost:8080/swagger-ui.html (adjust the port if your app uses a different one).
内容的提问来源于stack exchange,提问作者Subeen A




