• Java-IDEA环境搭建swagger


    1.项目POM导入包(使用Maven管理的代码)

      

    2.POM文件导入包 

     1 <dependencyManagement>
     2         <dependencies>
     3             <dependency>
     4                 <groupId>io.swagger</groupId>
     5                 <artifactId>swagger-annotations</artifactId>
     6                 <version>1.5.14</version>
     7             </dependency>
     8             <dependency>
     9                 <groupId>io.springfox</groupId>
    10                 <artifactId>springfox-swagger2</artifactId>
    11                 <version>2.7.0</version>
    12             </dependency>
    13             <dependency>
    14                 <groupId>io.springfox</groupId>
    15                 <artifactId>springfox-swagger-ui</artifactId>
    16                 <version>2.7.0</version>
    17             </dependency>
    18 
    19         </dependencies>
    20     </dependencyManagement>

    3.启动项目导入pom文件

     1     <dependencies>
     2         <dependency>
     3             <groupId>io.swagger</groupId>
     4             <artifactId>swagger-annotations</artifactId>
     5         </dependency>
     6         <dependency>
     7             <groupId>io.springfox</groupId>
     8             <artifactId>springfox-swagger2</artifactId>
     9         </dependency>
    10         <dependency>
    11             <groupId>io.springfox</groupId>
    12             <artifactId>springfox-swagger-ui</artifactId>
    13         </dependency>
    14     </dependencies>

    4.WebConfig 配置

     1  /**
     2      * 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。
     3      * 需要重新指定静态资源
     4      * @param registry
     5      */
     6     @Override
     7     public void addResourceHandlers(ResourceHandlerRegistry registry) {
     8         registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
     9         registry.addResourceHandler("swagger-ui.html")
    10                 .addResourceLocations("classpath:/META-INF/resources/");
    11         registry.addResourceHandler("/webjars/**")
    12                 .addResourceLocations("classpath:/META-INF/resources/webjars/");
    13         super.addResourceHandlers(registry);
    14     }

    5.增加启动的注入扫描 (@EnableSwagger2)

     6.项目启动后运行效果,查看swagger

    7.接口参数相关效果

    8.代码接口配置(更多配置注解请查看 https://blog.csdn.net/xiaojin21cen/article/details/78654652

  • 相关阅读:
    Apache 2.4+php 5.4 安装
    Linux 进程状态
    解决Redhat Linux AS使用yum时出现This system is not registered with RHN的问题(改用CentOS的yum)
    nagios 事件处理
    awk调用shell命令的两种方法:system与print
    磁盘性能分析
    如何通过JQuery将DIV的滚动条滚动到指定的位置
    GCC Windows Linux 下编译学习1
    Linux命令
    GCC Windows Linux 下编译学习2
  • 原文地址:https://www.cnblogs.com/shexunyu/p/11022423.html
Copyright © 2020-2023  润新知