• swagger在zuul网关中的集成


    1.导包

    <!--引入swagger支持-->
                <dependency>
                    <groupId>io.springfox</groupId>
                    <artifactId>springfox-swagger2</artifactId>
                    <version>2.9.2</version>
                </dependency>
                <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
                <dependency>
                    <groupId>io.springfox</groupId>
                    <artifactId>springfox-swagger-ui</artifactId>
                    <version>2.9.2</version>
                </dependency>

    2.写入配置类

    需要两个配置类

    DocumentationConfig

    package cn.jiedada.hrm.config;
    
    import org.springframework.context.annotation.Primary;
    import org.springframework.stereotype.Component;
    import springfox.documentation.swagger.web.SwaggerResource;
    import springfox.documentation.swagger.web.SwaggerResourcesProvider;
    
    import java.util.ArrayList;
    import java.util.List;
    
    @Component
    @Primary
    public class DocumentationConfig implements SwaggerResourcesProvider {
        @Override
        public List<SwaggerResource> get() {
            List resources = new ArrayList<>();
            //添加所有的微服务的文档资源
            /**
             * 参数:
             * name:自定义的服务的名字
             * location:指定是微服务的路径  在我们的配置文件中的zuul中的前缀和服务的别名
             * /前缀/服务名/v2/api-docs
             */
            resources.add(swaggerResource("系统管理", "/hrm/systemmanage/v2/api-docs", "2.0"));
            resources.add(swaggerResource("人力支援", "/hrm/hrmmm/v2/api-docs", "2.0"));
    
            return resources;
        }
    
        private SwaggerResource swaggerResource(String name, String location, String version) {
            SwaggerResource swaggerResource = new SwaggerResource();
            swaggerResource.setName(name);
            swaggerResource.setLocation(location);
            swaggerResource.setSwaggerVersion(version);
            return swaggerResource;
        }
    }

    SwaggerConfig

    package cn.jiedada.hrm.config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    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 SwaggerConfig {
    
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo());
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("源码人力资源综合平台")
                    .description("源码人力资源综合平台接口文档说明")
                    .termsOfServiceUrl("http://localhost:1020")
                    .contact(new Contact("jiedada", "", "jiedada@jiedada.cn"))
                    .version("1.0")
                    .build();
        }
    }

    3.访问方式

    localhost:1020/swagger-ui.html

  • 相关阅读:
    C# 模拟浏览器请求
    关于获取时间后,时间格式为几天前,几小时前格式转化
    关于通用的C#后台获取前台页面的标签的正则表达式
    关于getHTML()方法和getHtmlAjax()方法 GetHttpLength, 清除HTML标签
    性能测试术语
    聚合报告中90% Line涉及到百分位数的概念
    使用Windows的cmd运行(或通过批处理启动)Python项目(多目录项目)提示找不到模块的解决办法
    OSError: [WinError 6] 句柄无效的解决办法
    python中日志输出重复的解决办法
    截图方法get_screenshot_as_file()注意点
  • 原文地址:https://www.cnblogs.com/xiaoruirui/p/11962572.html
Copyright © 2020-2023  润新知