最近使用SpringBoot2.6.2集成Swagger时报错,报错信息如下:
解决办法:参考某博主的链接
spring: mvc: pathmatch: matching-strategy: ant_path_matcher
最近,留意到身边的同学在使用Knife4j,说用起来感觉很棒!还推荐我去用,所以,就趁着今天的机会试试!
1、导入依赖
方式一:maven
com.github.xiaoymin knife4j-spring-boot-starter3.0.3
方式二:gradle(为什么用gradle?官方说gradle速度比maven快,就写来玩玩)
// knife4j implementation 'com.github.xiaoymin:knife4j-spring-boot-starter:3.0.3'
2、Knife4j配置
# knife4j knife4j: # 开启增强模式 enable: true production: false # 开启BasicHttp验证 basic: enable: true username: admin password: 123456
@Configuration @EnableKnife4j public class Knife4jConfig { @Bean public Docket docket(Environment environment) { //设置要显示swagger的环境 Profiles of = Profiles.of("dev", "test"); //判断当前是否处于该环境 boolean b = environment.acceptsProfiles(of); // 创建 Docket return new Docket(documentationType.OAS_30) .enable(b) .apiInfo(apiInfo()) .groupName("default") .select() .apis(RequestHandlerSelectors.basePackage("com.simple.springboottest0102.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { Contact contact = new Contact("gyj", "https://www.xx.com", "[email protected]"); return new ApiInfoBuilder() .title("Knife4j的接口文档") .description("简单点,说话的方式简单点...") .termsOfServiceUrl("https://www.xx.com") .contact(contact) .version("1.0") .build(); } }
3、测试
文档地址:http://localhost:8080/doc.html
官方文档:https://doc.xiaominfo.com/knife4j/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)