-
-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
404 not found on swagger UI #361
Comments
Hi, You can have a look at the demos code: By default, you just need to add the dependency of the springdoc-openapi-ui. Are you also serving other static content on your spring-boot 2.2.2 application? If you can provide, a sample code to reproduce, it will be easier to answer. |
I was having almost the same issue, but http://localhost:8080//swagger-ui.html was also 404 despite the fact that my spring security configs were correct. My dependencies were really mixed. I had java 8 running with Spring Boot 2.1.6 and springdoc-openapi latest. When I migrated to java 13 with Spring Boot 2.2.2 everything started to work out of the box! |
@bnasslahsen why you use |
@trip2gafa, v1.2.28 is already avaialble on maven central: There is an indexation delay with https://mvnrepository.com, but this is only for search purposes. Can you please add more details about your request :
Thank you in advance. |
Im trying to find what causes this. I have been gradually stripping down the application piece by piece, and at one point im able to make it work. |
@dahlsdata You can just enable standard spring-boot logs : logging.level.web=TRACE
logging.level.org.springframework.web=TRACE If you don't find the cause, just provide a sample code (HelloController) or Test to reproduce the issue you are describing. |
@bnasslahsen I am using Here is my controller example:
|
Hmm, logging now turned on but not getting much wiser. Here is the log for my app where it works fine:
And the log from the app that doesnt work:
I cant see anything in there that helps me further debug this... Im also having problems assembling a sample for you to reproduce, as i must strip down the application a lot before i could send it somewhere and i havnt been able to do that yet without the issue going away... |
@bnasslahsen I enabled a logging stack trace and started an app. And now when I go to localhost:8080/swagger-ui.html, I have this stack trace:
I will glad if it helps. PS: There is a thing like |
The attached sample code uses exactly your description and is working fine: |
@bnasslahsen can you add examples by using gradle, also? Or it does not make a sense? |
There are no short term plans for adding examples using gradle. |
I am using gradle btw |
I am too) |
The interesting fact is http://localhost:8080/v3/api-docs works. There is something in a project which serves as an obstacle to show the swagger UI documentation page (http://localhost:8080/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config). |
|
http://localhost:8080/v3/api-docs works, but http://localhost:8080/v3/api-docs/swagger-config does not. |
No. just warning |
The working example with gradle as well :) |
@bnasslahsen |
This is your real exception, and not a warning. You have to debug, to find out the cause. |
Ok finally got this issue nailed down! It is classpath releated and it seems as it is related to a very large classpath. So in intellij (im using IntelliJ) i had set run-configuration shorten command line to "jar manifest". And then it (swagger-ui) does not work. (but application starts fine) Running with "none" as shorten command line also does not work as the application will not start at all then. Also when running from gradle "bootRun" it seems as gradle will use some sort of command-line shortening that results in application startup, but swagger-ui not working. But then if i change to "@argFiles (java9+)" in intellij run setting, then it works from IntelliJ, both application and swagger-UI. But from gradle bootRun it will still not work. With a smaller project, that does not need command line shortening, it also works from gradle bootRun. |
@dahlsdata did you have problems with DefaultErrorWebExceptionHandler? |
No, i cannot recall any DeafultErrorWebExceptionHandler. |
Seems I found problem
|
Looking at the swagger-ui dependency I saw that the index.html is nested under resources/webjars/swagger-ui/3.25.0
|
Even it is mentioned here #402 (comment) just adding @EnableWebFlux annotation only near any @configuration, triggers the SwaggerConfig.addResourceHandlers() inside springdoc-openapi-webflux-ui. In this case I didn't have to add resource handler manually by myself. But without @EnableWebFlux I couldn't succeed any further. |
@ahmetgeymen I saw that issue. The suggested solution did not work for me, because I was not using web flux. |
Adding this to my pom.xml helped . Eclipse+Spring webmvc {NAME_YOUR_PROJECT} org.springframework.boot spring-boot-maven-plugin build-info |
@SebasWebDev Thanks. In swagger-ui-{version}.jar, we can see index.html in directory META-INF/resources/webjars/swagger-ui/{version}/. So according to SebasWebDav's solution, /swagger-ui/index.html will redirect to /webjars/swagger-ui/{version}/index.html. In my case, I can access /swagger-ui/index.html, but I cannot browse /swagger-ui.html and then redirect to /swagger-ui/index.html. So I have to browse /swagger-ui/index.html, and input api docs's path, each time, in the top textbox, for example, /v3/api-docs, except when i browse /swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config. This isn't friendly. For a new springboot project, integrated with swagger 3, the default behavior is ,Browse /swagger-ui.html, and then redirect to /swagger-ui/index.html?configUrl=xxx&abc=def. Finally, i found org.springdoc.webmvc.ui.SwaggerWebMvcConfigurer in springdoc-openapi-ui-{version2}.jar, and there is a addResourceHandlers to do what SebasWebDav mentions. So when /swagger-ui/index.html return 404, i think it's worth checking whether SwaggerWebMvcConfigurer.addResourceHandlers is called, and if not, why. In my case, i code like the following, Finally I changed to the following, Hope it helpful. |
Also face this issue. IDEA doesnt see However its present in dependency tree [INFO] +- org.springdoc:springdoc-openapi-ui:jar:1.5.1:compile [INFO] | +- org.springdoc:springdoc-openapi-webmvc-core:jar:1.5.1:compile [INFO] | | \- org.springdoc:springdoc-openapi-common:jar:1.5.1:compile [INFO] | | +- io.swagger.core.v3:swagger-models:jar:2.1.6:compile [INFO] | | +- io.swagger.core.v3:swagger-annotations:jar:2.1.6:compile [INFO] | | +- io.swagger.core.v3:swagger-integration:jar:2.1.6:compile [INFO] | | | \- io.swagger.core.v3:swagger-core:jar:2.1.6:compile [INFO] | | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.11.2:compile [INFO] | | | \- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile [INFO] | | +- io.github.classgraph:classgraph:jar:4.8.69:compile [INFO] | | \- org.apache.commons:commons-lang3:jar:3.10:compile [INFO] | +- org.webjars:swagger-ui:jar:3.37.2:compile [INFO] | \- org.webjars:webjars-locator-core:jar:0.45:compile [INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.11.2:compile Simplest solution is to delete Or add this dependency directly to your pom / gradle build
Why IDEA doesn't see it - very strange - idk. |
This worked for me. |
Using the current version (1.5.6), i need to override the method in WebMvcConfigurationSupport in the following way:
without it, spring boot returns 404 |
If you are having issues, this means your project is not well configured. You have many demos available, depending on your context. You can follow the guidance, section Using GitHub Issues, if you need help. |
Running Spring Boot 2.2.2 with org.springdoc:springdoc-openapi-ui:1.2.26
http://localhost:8069/v3/api-docs/swagger-config -> 200 OK
http://localhost:8069/v3/api-docs -> 200 OK
http://localhost:8069/swagger-ui.html -> 302 -> http://localhost:8069/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config -> 404 Not found.
All i did was adding springdoc-openapi-ui to an existing spring boot 2.2.2 application. No configuration done at all.
Ive been reading the docs, but cannot see if im doing something wrong or if this is a bug.
The text was updated successfully, but these errors were encountered: