springboot 整合knife4j

1.在项目pom文件引入依赖包

<dependency>
  <groupId>com.github.xiaoymin</groupId>
  <artifactId>knife4j-spring-boot-starter</artifactId>
  <version>2.0.9</version>
</dependency>

2.在配置文件application.properties中加入以下配置

spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

如果是application.yml就加入

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

3.配置SwaggerConfig配置文件


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author fy
 */
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

  @Bean(value = "defaultApi2")
  public Docket defaultApi2() {
    String groupName = "2.X版本";
    return new Docket(DocumentationType.SWAGGER_2)
        .host("https://www.baidu.com")
        .apiInfo(apiInfo())
        .groupName(groupName)
        .select()
            // TODO 指向接口包
        .apis(RequestHandlerSelectors.basePackage("com.jhy.fsms"))
        .paths(PathSelectors.any())
        .build()
        ;
    //赋予插件体系
//        .extensions(openApiExtensionResolver.buildExtensions(groupName));
  }

  private ApiInfo apiInfo() {
    String title = "内网平台接口";
    try {
      InetAddress addr = InetAddress.getLocalHost();
      title = addr.getHostName();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
    return new ApiInfoBuilder().title(title)
        .description("接口")
//        .termsOfServiceUrl("http://localhost:8090/swagger-ui.html")
//        .contact(new Contact("fms", "https://qiye.aliyun.com/", "jw@seastart.cn"))
        .version("1.1.0")
        .build();
  }
}

4进入http://127.0.0.1:8099/doc.html#/home

成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值