What is the method to integrate swagger with Spring Boo…

There are several steps to integrate Swagger with Spring Boot.

  1. the pom.xml file in English
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-boot-starter</artifactId>
   <version>3.0.0</version>
</dependency>
  1. Create a Swagger configuration class: Set up a Swagger configuration class to define the information and rules for Swagger. See example code below:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))              
          .paths(PathSelectors.any())                          
          .build();
    }
}

In the above code, the basePackage method specifies the package path that needs to be documented, which can be modified according to actual needs.

  1. Enable Swagger 2
@SpringBootApplication
@EnableSwagger2
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
  1. The website address for accessing the Swagger interface on a local server is http://localhost:8080/swagger-ui.html

Note: In the above example, Swagger 2.x version is used. If using Swagger 3.x version, dependencies and configuration classes need to be adjusted accordingly.

bannerAds