1. Why use “SpringDoc OpenAPI”, Not use “SpringFox” libraries
Both SpringDoc OpenAPI and SpringFox libraries are popular choices for integrating Swagger with Spring Boot applications. However, there are a few key differences between them:
1.Spring Boot 3.x.x Support: SpringDoc OpenAPI provides better support for Spring Boot 3.x versions, while SpringFox has limited support for Spring Boot 3.x. If you’re using Spring Boot 3.x, SpringDoc OpenAPI is the recommended option.
2.Maintenance and Updates: SpringDoc OpenAPI is actively maintained and regularly updated, while SpringFox seems to be less actively maintained in recent times. This means that SpringDoc OpenAPI is more likely to receive bug fixes and new features, making it a more reliable choice in the long run.
3.Configuration: SpringDoc OpenAPI provides auto-configuration and uses annotations for configuration, while SpringFox typically requires a dedicated configuration class. This can make SpringDoc OpenAPI easier to set up and configure.
Considering these factors, if you’re using Spring Boot 3.x.x or looking for a library that is actively maintained, has good community support, and offers easier configuration, SpringDoc OpenAPI would be the better choice for your project.
2. Configuration Dependencies
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
3. Controller Code
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class MyController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
4. Accessing the Swagger UI
After starting your Spring Boot application, you can visit Swagger UI to view the automatically generated API documentation. By default, Swagger UI can be accessed at the following URL:
http://localhost:8080/swagger-ui.html