Search code examples
javaspringspring-bootswagger-ui

Spring Boot 3 springdoc-openapi-ui doesn't work


I'm trying to add swagger-ui (OpenAPI 3.0) to a Spring Boot v3 application.

I've added the openapi-ui maven dependency, and it should work as per the documentation.

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

But apparently, it still doesn't work and localhost:8080/swagger-ui.html returns an 404 error.

What am I missing?

enter image description here


Solution

  • According to the documentation:

    For spring-boot 3 support, make sure you use springdoc-openapi v2

    What is the compatibility matrix of springdoc-openapi with spring-boot?

    For the integration between spring-boot and swagger-ui, add the library to the list of your project dependencies (No additional configuration is needed)

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.0.0</version>
    </dependency>
    

    This will automatically deploy swagger-ui to a spring-boot application:

    Documentation will be available in HTML format, using the official swagger-ui jars

    The Swagger UI page will then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs

    server: The server name or IP
    
    port: The server port
    
    context-path: The context path of the application
    
    Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml
    

    Please note that modules have been renamed:

    https://springdoc.org/#migrating-from-springdoc-v1

    enter image description here