java - 如何从javadocs生成Swagger UI?

标签 java spring-boot intellij-idea swagger swagger-ui

我可以通过@Api@ApiOperation批注在Spring引导应用程序上生成swagger UI。

这些注释使代码有点脏。我想知道如何从javadocs为我的API端点生成详尽的文档。

最佳答案

有一个简单的方法,您必须添加@ EnableSwagger2批注。

  • 您可以在pom.xml中添加以下依赖项
       <dependency>
          <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.9.2</version>
            </dependency>
    
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
    
  • 在Spring Boot应用程序的主类中添加以下注释。
    @EnableSwagger2
    public class Authentic {
    
        public static void main(String[] args) {
            SpringApplication.run(Authentic.class, args);
        }
    }
    
    
  • 以下是访问API文档的方法。

  • 例如网址:http://localhost:8080/swagger-ui.html#/

    enter image description here

    关于java - 如何从javadocs生成Swagger UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56788268/

    相关文章:

    java - 在哪里放置 Maven 参数化 junit 输入 xml 文件

    java - 学习 Ant - 资源

    java - 如何在 Spring Boot 2 oauth2 中获取 token ?

    java - 从 Spring boot 单元测试中排除 Spring Cloud Config Server

    java - 部署具有 JSON 文件的 Java 项目的正确方法是什么?

    AndroidStudio 告诉我我的模拟器与我的项目不兼容,为什么,如果模拟器是 api10 而项目是 api3?

    intellij-idea - 在失败的 JUnit 测试期间使 IntelliJ 显示完整的堆栈跟踪

    java - Ubuntu 上的 MySQL 异常 : com. mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链路故障

    java - 使用 Apache Tika 解析 iWorksDocument 时出现问题

    java - Spring Boot启动缓存未触发