Trouble configuring springdoc-openapi with Spring Boot 3.2.2

499 Views Asked by At

I am working on a Spring Boot project which has Rest APIs. It's a backend project.

I am configuring OpenAP I3.0 as per the documentation here https://springdoc.org/#Introduction

I have included this dependency in my pom.xml:

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

I am using maven to build the project. It downloads necessary jars, then I started the application but when I am accessing this link http://localhost:8080/swagger-ui/index.html

I am getting this:

There was an unexpected error (type=Not Found, status=404). No static resource swagger-ui/index.html. org.springframework.web.servlet.resource.NoResourceFoundException: No static resource swagger-ui/index.html.`

I tried to use these properties inside my application.yml but the result is still same.

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

I do not understand why this is not working because as per documentation it should work once we have added dependency and build the project.

Note: I do not have any configuration class yet. Just a RestController and Service Class. And, as of now I am not using spring-security. I am using springboot-maven-plugin.

Also one strange thing which I noticed that when the application jar file is created, there is no resource folder inside META-INF. Maybe it is looking for index.html inside that resource folder and that is causing the issue but I am not sure.

2

There are 2 best solutions below

2
work-in-progress On

got the same error

14-03-2024 12:51:15.483 [http-nio-8080-exec-4] DEBUG org.springframework.web.servlet.resource.ResourceHttpRequestHandler | Resource not found
14-03-2024 12:51:15.483 [http-nio-8080-exec-4] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver | Resolved [org.springframework.web.servlet.resource.NoResourceFoundException: No static resource swagger-ui/index.html.]
14-03-2024 12:51:15.484 [http-nio-8080-exec-4] DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor | Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
14-03-2024 12:51:15.484 [http-nio-8080-exec-4] DEBUG org.springframework.web.servlet.DispatcherServlet | Completed 404 NOT_FOUND

it's remarkable that I have another project that works, searching for a solution

0
Rodrigo Sene On

I had the same problem using Spring boot 3.2 and org.springdoc:springdoc-openapi-ui 1.8.0. It seems like the problem is related to some conflict version with spring boot.

In my case, I changed the Spring doc dependency to org.springdoc:springdoc-openapi-starter-webmvc-ui:2.4.0, after it worked fine.

Be sure to allow the necessary URL in the security configuration.