springboot集成swagger

发布时间:2024-09-04 16:01

Swagger依赖包

		
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger2artifactId>
            <version>2.9.2version>
        dependency>
        <dependency>
            <groupId>io.springfoxgroupId>
            <artifactId>springfox-swagger-uiartifactId>
            <version>2.8.0version>
        dependency>
        <dependency>
            <groupId>com.github.xiaoymingroupId>
            <artifactId>swagger-bootstrap-uiartifactId>
            <version>1.9.6version>
        dependency>
package com.sh.content.config;

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

/**
 * @author shs-xxaqbzylh4
 */
@Configuration
@EnableSwagger2
@Profile(\"test\") // todo 这个是分环境来访问的,test代表只能在测试环境访问swagger
public class SwaggerConfig {

    /**
     * 创建API应用
     * apiInfo() 增加API相关信息
     * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
     * 本例采用指定扫描的包路径来定义指定要建立API的目录。
     *
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(\"com.baidu.content-back.controller\"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建该API的基本信息(这些基本信息会展现在文档页面中)
     * 访问地址:http://127.0.0.1:7021/content-back/doc.html todo content-back 是我的项目路径
     *
     * @return
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact(\"name\", \"网址\", \"邮箱\");
        return new ApiInfoBuilder()
                .title(\"标题\")
                .description(\"描述\")
                .termsOfServiceUrl(\"http://127.0.0.1:7021/content-back/doc.html\")
                .contact(contact)
                .version(\"1.0\")
                .build();
    }
}

启动项目访问地址http://127.0.0.1:7021/content-back/doc.html

\"springboot集成swagger_第1张图片\"

分环境访问问题,test是我的测试环境,大家根据实际情况来,而且这种只是接口文档不会加载,其他css还是会加载的,如果有其他硬性要求建议换方案来实现接口文档仅在测试环境访问
\"springboot集成swagger_第2张图片\"

你可能感兴趣的

相关推荐

基于FPGA的实时图像边缘检测系统设计(上)

【STL】map和set的使用

13天进阶Java笔记-day2-抽象类、接口、代码块、final、单例、枚举

位运算符讲解

Transformer新型神经网络在机器翻译中的应用 | 百万人学AI

详解Vue与element-ui整合方式

Vue 之 echarts 图表数据可视化的基础使用(简单绘制各种图表、地图)

Hive--06---分区表、分桶表

Java实现API sign签名校验的方法详解

Python OpenCV Canny边缘检测算法的原理实现详解

maven的插件

<引用>《C++初阶》

解决vue3使用element-ui

一键自动化数据分析!快来看看这些宝藏工具库

Docker 部署 Nginx 反向代理

PyTorch】常见错误: RuntimeError:one of the variables needed for gradient computation has been modified

【day_5:求范围内的随机正负整数,拍平数组,拍平数组(按需拍平,纯js算法版)-返回一个 十六进制 的 随机颜色】

代码审计实战积累

不小心被拉进QQ诈骗群之后

关于js默认值

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号