栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Swagger

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Swagger

1、Swagger简介


2、springboot集成swagger (1)、pom中导入swagger包

            io.springfox
            springfox-swagger2
            3.0.0
        
        
            io.springfox
            springfox-swagger-ui
            2.9.2
        
(2)、配置swagger->config
package com.example.swagger.config;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2   //开启swagger
public class SwaggerConfig {
}

(3)、写@Contrller进行测试
package com.example.swagger.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ApiController {
    @GetMapping("/testApi")
    public String test(){
        return "测试swagger";
    }
}

(4)、启动项目发现失败
org.springframework.context.ApplicationContextException:
 Failed to start bean 'documentationPluginsBootstrapper';
  nested exception is java.lang.NullPointerException

在application.yml中或者application.properties中加入配置修改升级之后的版本与springboot不兼容的问题

spring.mvc.pathmatch.matching-strategy=ant_path_matcher
(5)、重新启动项目测试

访问ip http://localhost:8001/swagger-ui.html,失败

更换版本,解决问题(但是在application.yml中或者application.properties中加入有关swagger的配置不能删除,否则即使降低版本也会依然报错)

 
            io.springfox
            springfox-swagger2
            2.9.2
        
        
            io.springfox
            springfox-swagger-ui
            2.9.2
        


所以归根结底是版本的问题才导致出现一系列的问题!但是要注意即使更换版本,在application.yml中或者application.properties中加入有关swagger的配置spring.mvc.pathmatch.matching-strategy=ant_path_matcher依然不能删除
可以看到通过访问ip http://localhost:8001/swagger-ui.html看到我们自己写的@Controller中有多少个api接口,更方便团队合作开发!

3、配置swagger
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1013914.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号