2024.5.31 Friday
Following up on【WEEK14】 【DAY4】Swagger Part 2【English Version】
Contents
16.6. Configure API Groups
16.6.1. Modify SwaggerConfig.java
package com.P47.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
@Configuration // Equivalent to @Component
@EnableSwagger2 // Enable Swagger2
public class SwaggerConfig {
// Configure the bean instance Docket for Swagger, to set specific parameters for Swagger
@Bean
public Docket docket(Environment environment){
// Set the environments where Swagger should be displayed
Profiles profiles = Profiles.of("dev", "test");
// Determine if the current environment matches the profiles
// Use enable() to accept this parameter and decide whether to display
boolean flag = environment.acceptsProfiles(profiles);
flag=true; // To access through port 8080, and because the dev and test profile ports do not include 8080, manually set flag to true to ensure enable(flag) starts normally.
return new Docket(DocumentationType.SWAGGER_2) // See the source code in DocumentationType.classpublic class DocumentationType extends SimplePluginMetadata method, select the appropriate version for editing
.apiInfo(apiInfo()) // Public Docket(DocumentationType documentationType) method, click on ApiInfo to go to ApiInfo.class
.enable(flag) // Whether to enable Swagger, if false it cannot be started, and the page shows:
标签:return,WEEK14,DAY5,annotations,Part,import,Swagger,Docket,public
From: https://blog.csdn.net/2401_83329143/article/details/139350056