How to integrate Swagger documentation in SpringBoot?
You can integrate Swagger documentation in SpringBoot by following these steps:
- Add Swagger dependency:
Add Swagger dependency to the project’s pom.xml file.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
- Configure Swagger:
Add Swagger configuration in the SpringBoot configuration class, for example:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.controller"))
.paths(PathSelectors.any())
.build();
}
}
- To start the application:
After launching the SpringBoot application, simply visit http://localhost:8080/swagger-ui/index.html to view the Swagger documentation.
By following the above steps, you can integrate Swagger documentation into your Spring Boot application, which can help developers easily view and test API interfaces.