SpringBoot集成knife4j

1)添加knife4j的依赖

<dependency>
  <groupId>com.github.xiaoymingroupId>
  <artifactId>knife4j-spring-boot-starterartifactId>
  <version>3.0.2version>
dependency>

SpringBoot的版本:

<parent>
    <artifactId>spring-boot-starter-parentartifactId>
    <groupId>org.springframework.bootgroupId>
    <version>2.7.3version>
parent>

2)添加knife4j的配置类

@Configuration
public class Knife4jConfig {
    @Bean
    public Docket docket() {
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("测试项目接口文档")
                .version("2.0")
                .description("测试项目接口文档")
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.github.xjs.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

}

3)application.yml中设置springmvc的路径匹配规则

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

done!
测试代码下载:https://github.com/xjs1919/enumdemo下面的knife4j-demo

你可能感兴趣的:(spring,boot,后端,java)