Knife4j integrates springboot

References

Integrated use of knife4j_knife4jconfiguration-CSDN Blog

SpringBoot integrates knife4j_knife4j-spring-boot-starter-CSDN blog

Introduce maven

 <!--introduceKnife4jofficialstartBag,This guide selectsSpring BootVersion<3.0,Developers need to pay attention-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
            <version>4.4.0</version>
        </dependency>

Configure Knife4jConfiguration

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
    @Bean(value = "dockerBean")
    public Docket dockerBean() {
        //designated useSwagger2specification
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        //Description field supportMarkdowngrammar
                        .description("# Knife4j RESTful APIs")
                        .termsOfServiceUrl("https://doc.xiaominfo.com/")
                        .contact("xiaoymin@foxmail.com")
                        .version("1.0")
                        .build())
                //Group Name
                .groupName("User service")
                .select()
                //Specify hereControllerScan package path
                .apis(RequestHandlerSelectors.basePackage("com.dr.code.diff.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

Configure whitelist to allow Knife4j requests

Resources that need to be released

1. doc.html,/swagger-ui.html
2. Various js css gif, etc., these are actually in /webjars/**
3.v2/api-docs interface
4. /swagger-resources

Configure access to static resources

// When accessing static resources,Directly access corresponding local resources
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}

Release knife4j requests (including static resources)

// To be added

Place application.yaml

// To be added