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

公共模块配置swagger测试

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

公共模块配置swagger测试

在项目中添加依赖

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

在公共模块中创建子模块service_utils

添加测试类

package com.lzq.yygh.common.config;

import com.google.common.base.Predicates;
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.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;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket webApiConfig(){
        return new Docket(documentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                //只显示api路径下的页面
                //.paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }
    @Bean
    public Docket adminApiConfig(){
        return new Docket(documentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }
    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("网站-API文档")
                .description("本文档描述了网站微服务接口定义")
                .version("1.0")
                .contact(new Contact("lzq", "http://123.com", "1938760862@qq.com"))
                        .build();
    }
    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("后台管理系统-API文档")
                .description("本文档描述了后台管理系统微服务接口定义")
                .version("1.0")
                .contact(new Contact("lzqz", "http://123.com","1938760862@qq.com"))
                        .build();
    }
}

因为测试service所以在service添加依赖


    com.lzq
    service_utils
    0.0.1-SNAPSHOT

因为启动类在service,所以common模块中配置注解也不会随类启动而加载

在启动类加入注解

@ComponentScan(basePackages = {"com.lzq"})

因为依赖引入所以会加载

测试

http://localhost:8201/swagger-ui.html

添加中文注释

在控制层上

@Api(tags = "医院设置接口")

方法上

@ApiOperation(value = "医院设置列表)

参数上

public boolean removeById(@ApiParam(name = "id", value = "医院id", required = true)@PathVariable String id)

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

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

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