We have a spring boot 2.2.1 application that delivers javascript at /.
As soon as we add the dependency 'org.springdoc:springdoc-openapi-ui:1.2.16'
the static content is no longer delivered. We get a 404 instead.
If there is a conflict with an existing configuration, you can just change the following property:
springdoc.swagger-ui.path=/you-path/swagger-ui.html
I'm not sure this is a valid solution. An application that has any kind of static content within src/main/resources/static no longer is served. Instead you get a 404. Changing the springdoc.swagger-ui.path property doesn't fix this.
There is something going on where springdoc is doing something with the ResourceHttpRequestHandler that Spring Boot configures and removes all the standard paths for static resource serving. When I put breakpoints at app startup inside ResourceHttpRequestHandler I see that there are multiple instances created. When ResourceHttpRequestHandler.handleRequest is invoked on a static resource, the instance that serves the request doesn't have any of the pre-configured locations defined in https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content
This ticket needs to be re-opened. This issue is a blocker for me. I can not use this library if I can't serve static content.
Can you please provide a sample code HelloController, that helps reproducing the behavior you are racing because we are not able to reproduce it.
The issue can be consquently reopened.
I'll do you one better - I'll give you the entire sample application.
https://github.com/edeandrea/summit-lab-spring-music is the repo that contains the code. It is a simple Spring MVC application with some Angular UI stuff in src/main/resources/static as well as a few @RestControllers. It also uses Spring Data JPA. It is an updated version of the Spring Music sample application.
The pipeline branch has the springdoc-openapi-ui dependency removed and the @Configuration class with the OpenAPI configuration commented out. The ApplicationTests test class runs to success and when running the app (http://localhost:8080) you see the UI.
The springdoc-issue branch has the springdoc-openapi-ui dependency added back in and the OpenAPIConfig class has been uncommented, although the presence of the OpenAPIConfig class doesn't even matter. Simply adding the springdoc-openapi-ui dependency and things start to not work. The ApplicationTests test class fails
MockHttpServletRequest:
HTTP Method = GET
Request URI = /index.html
Parameters = {}
Headers = []
Body = null
Session Attrs = {}
Handler:
Type = org.springframework.web.servlet.resource.ResourceHttpRequestHandler
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 404
Error message = null
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers"]
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
and when running the app and going to http://localhost:8080 will give you a 404.
When I was trying to troubleshoot it I put a breakpoint in org.springframework.web.servlet.resource.ResourceHttpRequestHandler.afterPropertiesSet() and noticed that this breakpoint was hit 3 or 4 times on application startup. I also put a breakpoint in org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(HttpServletRequest, HttpServletResponse) when hitting the app and that breakpoint only fired once. When looking at the instance ids of the class, the instance that the handleRequest breakpoint hit, the locations attribute only had the /webjars path and not any of the other standard Spring Boot static location paths. When I remove the springdoc-openapi-uidependency and re-run in debug mode, when handleRequest is hit, the locations attribute has many things in it (classpath:/static/, classpath:/public, etc).
Hi @edeandrea,
Thank you for providing the sample to reproduce this issue.
It will fixed with the next release of the springdoc-openapi: v1.2.19.
Thanks!
I am facing the same problem. @edeandrea did that solve the problem? Using v1.2.19 is throwing following error during application boot-up:
Unable to read meta-data for class org.springdoc.core.SwaggerUiConfigProperties
I tried whatever the latest version was (newer than 1.2.19) and it worked fine.
Most helpful comment
I'm not sure this is a valid solution. An application that has any kind of static content within
src/main/resources/staticno longer is served. Instead you get a404. Changing thespringdoc.swagger-ui.pathproperty doesn't fix this.There is something going on where springdoc is doing something with the
ResourceHttpRequestHandlerthat Spring Boot configures and removes all the standard paths for static resource serving. When I put breakpoints at app startup insideResourceHttpRequestHandlerI see that there are multiple instances created. WhenResourceHttpRequestHandler.handleRequestis invoked on a static resource, the instance that serves the request doesn't have any of the pre-configured locations defined in https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-contentThis ticket needs to be re-opened. This issue is a blocker for me. I can not use this library if I can't serve static content.