Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Spring Boot java应用程序中启用swagger 2的问题_Java_Spring_Spring Boot_Swagger - Fatal编程技术网

在Spring Boot java应用程序中启用swagger 2的问题

在Spring Boot java应用程序中启用swagger 2的问题,java,spring,spring-boot,swagger,Java,Spring,Spring Boot,Swagger,我希望你们都做得很好。我试图在我的弹簧靴中实现昂首阔步,但不知何故,我无法让它工作。我采取了我应该采取的所有步骤,现在坚持一天真的很令人沮丧。详情如下 添加依赖项 创建具有要扫描的Docket对象的bean 我的servlet上下文路径是 server: servlet: context-path: /account 我尝试了所有可能的招摇过市的URL,比如http://localhost:8080/swagger-ui.html,http://localhost:8080/ac

我希望你们都做得很好。我试图在我的弹簧靴中实现昂首阔步,但不知何故,我无法让它工作。我采取了我应该采取的所有步骤,现在坚持一天真的很令人沮丧。详情如下

  • 添加依赖项
  • 创建具有要扫描的Docket对象的bean
  • 我的servlet上下文路径是

    server:
      servlet:
        context-path: /account
    
    
    我尝试了所有可能的招摇过市的URL,比如
    http://localhost:8080/swagger-ui.html
    http://localhost:8080/account/swagger-ui.html
    http://localhost:8080/account/v2/api-文档
    。所有这些都不起作用。如果我遗漏了什么或做错了什么,请告诉我好吗。我会非常感激的


    感谢~~

    Swagger 2.9.2在spring boot 2.0及以上版本中无法正常工作,因此我已切换到Open API。它只需要两个步骤

    1.添加依赖项

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.3</version>
    </dependency>   
    

    您可以尝试将依赖项更新到此文件吗

         <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-webmvc</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>
    
    
    伊奥·斯普林福克斯
    springfox-Swagger 2
    3.0.0-SNAPSHOT
    编译
    伊奥·斯普林福克斯
    springfox招摇过市用户界面
    3.0.0-SNAPSHOT
    编译
    伊奥·斯普林福克斯
    SpringFoxSpringWebMVC
    3.0.0-SNAPSHOT
    

    而不是
    @EnableSwagger2
    ,用
    @EnableSwagger2WebMvc

    什么版本的spring boot替换它?如果将logging设置为debug,则可能会看到配置没有被拾取。MIt是2.3.1.RELEASE,实际上在日志中显示它是这样映射的:映射的URL路径[/v2/api文档]到方法[springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String,HttpServletRequest)]看起来像是在接受招摇,而不是UI。也许下面的博客可能会有帮助是的,在这种情况下,/v2/api文档的端点应该仍然可以工作,但事实并非如此:(我从未使用过Swagger 2,但它可能需要在POM中配置一个插件才能正常工作。
    server:
      servlet:
        context-path: /account
    
    
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.3</version>
    </dependency>   
    
     springdoc:
       version: '@springdoc.version@'
       api-docs:
         enabled: true
         path: /v3/api-docs
       swagger-ui:
         path: /swagger-ui.html
    
         <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-webmvc</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>