????????????????????????Spring Cloud Zuul?????????????????????????????????????????????Swagger???????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了????????????????????????Spring Cloud Zuul?????????????????????????????????????????????Swagger???????相关的知识,希望对你有一定的参考价值。

???????????????   eve   ??????   dock   tap   ??????   submit   base   amp   

?????????

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????api??????????????????????????????????????????????????????????????????????????????API????????????????????????????????????????????????API?????????????????????????????????swagger???????????????????????????,????????????????????????swagger??????????????????????????????????????????????????????

1???????????????

??????springBoot-user-zuul-swagger   ??????zuul???????????????   9501

?????? ls-prevention-check???????????????  ???   ??????1         ??????   8091 

??????microcloud-provider-company     ???   ??????2         ?????????8105

2???????????????

????????????????????????

????????????????????????????????????Swagger??????????????????jar?????????pom.xml?????????????????????

 

 1     <dependency>
 2             <groupId>io.springfox</groupId>
 3             <artifactId>springfox-swagger2</artifactId>
 4             <version>2.7.0</version>
 5     </dependency>
 6     <dependency>
 7             <groupId>io.springfox</groupId>
 8             <artifactId>springfox-swagger-ui</artifactId>
 9             <version>2.7.0</version>
10     </dependency>

 

 

???????????????????????????

???????????????????????????????????????????????????Swagger???????????????????????????swagger??????????????????

 

 1 @Configuration
 2 @EnableSwagger2
 3 public class SwaggerConfig {
 4 
 5     @Bean
 6     public Docket createRestApi() {
 7         return new Docket(DocumentationType.SWAGGER_2)
 8                 .apiInfo(apiInfo())
 9                 .select()
10                 .apis(RequestHandlerSelectors.basePackage("com.zyc.controller"))
11                 .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
12                 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
13                 .paths(PathSelectors.any())
14                 .build();
15     }
16 
17     private ApiInfo apiInfo() {
18         return new ApiInfoBuilder()
19                 .title("Hello??????api")
20                 .description("Hello????????????????????????")
21                 .contact(new Contact("vker", "", "[email protected]"))
22                 .version("1.0")
23                 .build();
24     }
25 
26     @Bean
27     UiConfiguration uiConfig() {
28         return new UiConfiguration(null, "list", "alpha", "schema",
29                 UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true, 60000L);
30     }
31 }

 

 

 ??????????????????????????????

????????????@EnableSwagger2

????????????????????????????????????????????????????????????

????????????

 1 @Api("Hello??????")
 2 @RestController
 3 @RequestMapping("/company")
 4 public class Hello {
 5     
 6     @ApiOperation(value="/get/hello??????")
 7     @GetMapping("/get/hello")
 8     public String hello() {
 9         return "Hello Zuul springBoot-microcloud-provider-company";
10     }
11     
12 }

 

????????????????????????????????????????????????????????????????????????

 1 @Api() ????????????????????????????????????swagger????????? 
 2 tags??????????????? 
 3 value??????????????????????????????tags?????? 
 4 
 5 @ApiOperation() ???????????????????????????http??????????????? 
 6 value?????????????????? 
 7 notes?????????????????? 
 8 
 9 
10 @ApiParam() ?????????????????????????????????????????????????????????????????????????????????????????????????????? 
11 name???????????? 
12 value??????????????? 
13 required???????????????
14 
15 @ApiModel()????????? ???????????????????????????????????????????????????????????? 
16 value?????????????????? 
17 
18 @ApiModelProperty()???????????????????????? ?????????model??????????????????????????????????????? 
19 value??????????????? 
20 name????????????????????? 
21 dataType????????????????????? 
22 required??????????????? 
23 example??????????????? 
24 hidden?????????
25 
26 @ApiImplicitParam() ???????????? 
27 ???????????????????????????
28 
29 @ApiImplicitParams() ??????????????????????????? @ApiImplicitParam 
30 name?????????ming 
31 value??????????????? 
32 dataType??????????????? 
33 paramType??????????????? 
34 example???????????????
35 
36 @ApiIgnore
37 ???????????????????????????????????????swagger?????????????????????

 

 

????????????????????????springBoot-user-zuul-swagger????????????????????????????????????DocumentationConfig

??????????????????????????????springBoot-user-zuul-swagger????????????Zuul??????????????????

 

 1 @Component
 2 @Primary
 3 public class DocumentationConfig implements SwaggerResourcesProvider{
 4 
 5     @Override
 6     public List<SwaggerResource> get() {
 7          List resources = new ArrayList<>();
 8             resources.add(swaggerResource("Hello??????", "/study-proxy/company-proxy/v2/api-docs", "1.0"));
 9             resources.add(swaggerResource("??????????????????", "/study-proxy/prevention-check/v2/api-docs", "1.0"));
10             return resources;
11     }
12 
13      private SwaggerResource swaggerResource(String name, String location, String version) {
14             SwaggerResource swaggerResource = new SwaggerResource();
15             swaggerResource.setName(name);
16             swaggerResource.setLocation(location);
17             swaggerResource.setSwaggerVersion(version);
18             return swaggerResource;
19      }
20 }

 

 

 

???????????????springBoot-user-zuul-swagger???application.yml????????????????????????

??????

1 spring:
2   application:
3     name: springBoot-user-zuul
4 zuul:
5   prefix: /study-proxy
6   ignored-services: "*"
7   routes: 
8     microcloud-provider-company: /company-proxy/**
9     ls-prevention-check: /prevention-check/**

 

??????????????????http://localhost:9501/swagger-ui.html

??????????????????

 





以上是关于????????????????????????Spring Cloud Zuul?????????????????????????????????????????????Swagger???????的主要内容,如果未能解决你的问题,请参考以下文章

象棋相关

s-s-rS 报告 - 从没有 s-s-rS 服务器的 C# 导出

字符串常用操作

s-s-rS 报告需要在 s-s-rS 2008 (VS 2008) 中重用来自 s-s-rS 2005 (VS 2005) 的 rdl 文件

安装后:无法在 wd %s %s (wd=%s) 中运行

正则表达式 (\S+?) 与 (\S+)) [重复]