springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.26k stars 493 forks source link

No static resource swagger-ui/index.html with springdoc 2.4.0 #2528

Closed nvervelle closed 6 months ago

nvervelle commented 6 months ago

Describe the bug

On our project, when upgrading from springdoc 2.3.0 to 2.4.0, access to swagger becomes broken. Using URL http://localhost:8080/swagger-ui/index.html :

{
  detail: "Internal Server Error",
  exceptionId: "869070aa-2794-454f-9fc7-16c780defc18",
  status: 500,
  timestamp: "2024-03-14T10:05:26.326404836Z",
  title: "Internal Server Error"
}

Stack trace :

{
  "timestamp":"2024-03-14T10:05:26.32324657Z",
  "message":"No static resource swagger-ui/index.html.",
  "logger":"xxx.SpringServerErrorHandler",
  "thread":"http-nio-8080-exec-5",
  "level":"ERROR",
  "stack_trace":"
    o.s.w.s.r.NoResourceFoundException: No static resource swagger-ui/index.html.\n\tat 
    o.s.w.s.r.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:585)\n\tat 
    o.s.w.s.m.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:52)\n\tat 
    o.s.w.s.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)\n\tat 
    o.s.w.s.DispatcherServlet.doService(DispatcherServlet.java:979)\n\tat 
    o.s.w.s.FrameworkServlet.processRequest(FrameworkServlet.java:1014)\n\tat 
    o.s.w.s.FrameworkServlet.doGet(FrameworkServlet.java:903)\n\tat j.s.http.HttpServlet.service(HttpServlet.java:564)\n\tat 
    o.s.w.s.FrameworkServlet.service(FrameworkServlet.java:885)\n\tat j.s.http.HttpServlet.service(HttpServlet.java:658)\n\tat 
    o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205)\n\tat 
    o.a.c.c.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)\n\tat o.a.t.w.s.WsFilter.doFilter(WsFilter.java:51)\n\tat 
    o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)\n\tat 
    o.a.c.c.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)\n\tat 
    o.s.w.f.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)\n\tat 
    o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)\n\tat 
    o.a.c.c.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)\n\tat 
    o.s.w.f.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\n\tat 
    o.s.w.f.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat 
    o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)\n\tat 
    o.a.c.c.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)\n\tat 
    o.s.w.f.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\n\tat 
    o.s.w.f.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)\n\tat 
    o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)\n\tat 
    o.a.c.c.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)\n\tat 
    o.s.w.f.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:109)\n\tat 
    o.s.w.f.OnceP...\n",
  "process.id":"869070aa-2794-454f-9fc7-16c780defc18"
}

To Reproduce Steps to reproduce the behavior:

Expected behavior

Additional context It may be related to problems on swagger-ui 5.11.8 (issue) but the description of the problem is different.

bnasslahsen commented 6 months ago

@nvervelle,

Not reproducible. Feel free to provide a Minimal, Reproducible Example - with HelloController that reproduces the problem.

This ticket will be closed, but can be reopened if your provide the reproducible sample.

madduci commented 6 months ago

@bnasslahsen I'm experiencing the same Problem with SpringBoot 3.2.4 and SpringDoc 2.4.0. The /v3/api-docs endpoint works, but the /swagger-ui/ doesn't.

I've built a minimum example demonstrating the issue, here: https://github.com/madduci/springdoc-springboot-bug

The bug occurs with Java 17 and Java 21 on Windows 10 with Maven 3.9.6

nvervelle commented 6 months ago

Hi @bnasslahsen . Can the issue be reopened as an example as been provided demonstrating the problem ?

bnasslahsen commented 6 months ago

@nvervelle,

The issue is not reproducible:

image
nvervelle commented 6 months ago

@bnasslahsen

Argh, you mean with the provided sample, you do not reproduce ? Can you tell me on which OS you tested ? On my side, the problem occurs on Linux (Ubuntu for my development computer, oracle java image for production). Built with gradle, JDK 20, spring boot 3.2

madduci commented 6 months ago

@nvervelle,

The issue is not reproducible: image

interesting. What is your environment (OS / Maven / JDK version)?

I can consistently reproduce the error on my Windows 10 machine

bnasslahsen commented 6 months ago
image
nvervelle commented 6 months ago

@bnasslahsen , given the differences depending on the OS in the posts above, we tested with our own application, running on docker compose locally, wth springdoc 2.4.0 :

Do you have the ability to test on Linux or Windows ?

bnasslahsen commented 6 months ago

@nvervelle,

It's all deployed on Linux https://springdoc.org/#demos

nvervelle commented 6 months ago

OK :thinking:

madduci commented 6 months ago

Update: with the 2.5.0 Version, it works for me again! Thank you @bnasslahsen

petertogara commented 4 months ago

Real issue is on the dependencies. For Spring Boot 3+ : Use the springdoc-openapi-starter-webmvc-ui dependency

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

For Spring Boot 2+: Use springdoc-openapi-ui dependency:

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

Remember to add these to your application.yml

springdoc:
  api-docs:
    path: /v3/api-docs
  swagger-ui:
    path: /swagger-ui.html
    enable: true
  show-actuator: true
  packages-to-scan: com.mycompany.service.controller
anhefti commented 1 month ago

I still have this problem with:

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>3.3.2</version>
  </parent>
......
  <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.6.0</version>
  </dependency>

Java 17 on Windows 10. /v3/api-docs endpoint works, but the /swagger-ui/ doesn't.

annstriganova commented 3 weeks ago

https://github.com/springdoc/springdoc-openapi/issues/2528#issuecomment-2154283503 + adding <useJakartaEe>true</useJakartaEe> to each configuration of openapi-generator-maven-plugin solved the problem for me.

Lucas-Angelo commented 1 week ago

for spring boot 3 use 2.1.0

that solve my problem, 2.6.0 or anyone else return error "No static resource..."

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.1.0</version>
 </dependency>
DiegoYegros commented 3 days ago

In my case, it didn't work with springdoc-openapi-starter-webmvc-ui 2.0.3, 2.1.0 and 2.6.0, but it did work with 2.2.0 -- I'm running Ubuntu 24.04, JDK 21 and

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.4</version>
        <relativePath/>
    </parent>
cerib33 commented 13 hours ago

In my case, it doesn't work with springdoc-openapi-starter-webmvc-ui 2.0.2, 2.1.0, 2.4.0 and 2.6.0 I'm using spring-security with csrf activated spring-boot-starter-parent 3.3.3 Windows11, JDK 17

Path /app/swagger-ui/index.html Error Not Found Status 404 Message No static resource swagger-ui/index.html.

application.properties springdoc.swagger-ui.csrf.enabled=true springdoc.swagger-ui.enabled=true springdoc.swagger-ui.path=/swagger-ui.html