Search code examples
spring-bootspringdoc

springdoc integration not working as expected for springboot


I am following this to integrate springdoc in my springboot application.

Springboot version is 3.3.1 and I have added dependency:

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

Dependency tree:

[INFO] +- org.springdoc:springdoc-openapi-starter-webmvc-ui:jar:2.5.0:compile
[INFO] |  +- org.springdoc:springdoc-openapi-starter-webmvc-api:jar:2.5.0:compile
[INFO] |  |  \- org.springdoc:springdoc-openapi-starter-common:jar:2.5.0:compile
[INFO] |  |     \- io.swagger.core.v3:swagger-core-jakarta:jar:2.2.21:compile
[INFO] |  |        +- io.swagger.core.v3:swagger-annotations-jakarta:jar:2.2.21:compile
[INFO] |  |        +- io.swagger.core.v3:swagger-models-jakarta:jar:2.2.21:compile
[INFO] |  |        \- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.17.1:compile
[INFO] |  \- org.webjars:swagger-ui:jar:5.13.0:compile

But for me none of the links work:

http://localhost:8080/v3/api-docs
http://localhost:8080/swagger-ui/index.html

Both has 'This site can’t be reached' message on browser.

Do I need any extra configuration?


Solution

  • I always define the paths explicitly:

    springdoc:
      api-docs:
        path: /public/v3/api-docs
      swagger-ui:
        path: /public/swagger-ui.html
    

    and then they will be available under localhost:8080/public/swagger-ui/index.html


    Keep in mind that if you have defined the property context-path:

    server:
      servlet:
        context-path: /foo-service
    

    then it will be part of the url: localhost:8080/foo-service/public/swagger-ui/index.html


    Lastly make sure you are not getting 403 because of spring security (open the network tab to see the error codes)