springfox: 404 when use swagger2-ui with spring-boot-1.5.6
Please take the time to search the repository, if your question has already been asked or answered.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
Get localhost:8080/v2/api-docs is ok, but localhost:8080/swagger-ui.html returns 404 . Spring-boot version is 1.5.6.RELEASE
Steps to Reproduce
- Clone https://github.com/ihappyk/Springboot-practice.git
- Change the version of Swagger Jars to 2.6.1 in Pom.xml
- Start application via mvn spring-boot:run
- Open URL http://localhost:8080/api-docs
- Open URL http://localhost:8080/swagger-ui.html
Similar to the issue #1747
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 67 (20 by maintainers)
@ihappyk config class
pom.xml
swagger class config , put it spring run class same directory
i use spring-boot version 1.5.6.RELEASE,swagger2 2.7.0,has same problem,need add some config in WebConfiguration
it’s working
Remove this dependencies and update versions for both dependencies to 2.7.0. If you try localhost:8080/swagger-resources/{files} you will see work good, probably. 😃
I had the same problem. I was following this tutorial here http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api.
I had a default @RequestMapping from a leftover test that was mapped to the root of the application.
I removed that (no default @RequestMapping), ran again and everything was working fine. LESSON: no default root mapping with Swagger UI.
Use Spring Boot add the following code in the Application file can fix.
I use spring boot version 1.5.10.RELEASE,springfox version 2.8.0.
I removed @EnableWebMvc annotation and /swagger-ui.html worked like a charm.
I had the same problem on my own test project today. The root cause of my problem is that there is already a handler mapped at the base URL. (This handler seem to take precedence over the handler of swagger-ui). As a result, the swagger ui is hidden
The solution is simple: I remapped that handler at a different URL and voila, the swagger-ui.html is there!
Relavent dependency (Gradle): compile(“org.springframework.boot:spring-boot-starter-web:1.5.11.BUILD-SNAPSHOT”) compile (“io.springfox:springfox-swagger2:2.7.0”) compile (“io.springfox:springfox-swagger-ui:2.7.0”)
Clear maven repository cache and reinstall all dependencies again, issue disappeared.
By the way I change editor from eclipse java to eclipse j2ee. I don’t know if this would cause the issue.
I had the same problem: 404 on GET swagger-ui.html, spring boot 1.5.9 application, springfox-swagger2 and springfox-swagger-ui 2.7.0 dependencies. After trying many different things suggested by different people with no success, I finally found the problem. I had a class in a shared lib with
@ExceptionHandler
methods that contained the@EnableWebMvc
annotation. When I removed@EnableWebMvc
swagger-ui.html worked. :^) EDIT: The swagger-ui.html page also works with springfox 2.8.0.@dilipkrish Yes, in fact that was the issue in my case. Thank you 😃
Same issue to @denis111 @DemianTinkiel
swagger2 = 2.7.0 swagger-ui = 2.7.0 springBootVersion = ‘1.5.9.RELEASE’
All possible solutions are not worked.
application.yml
Operating System: Windows Browser: Edge, Chrome, Firefox
@adiIspas i am still facing the same issue. 👎
I created a sample application that uses Spring 5 Reactive WebFlux and Springfox 3.0.0-SNAPSHOT that gets around the 404 issue for swagger-ui.html https://github.com/mpanicker/reactive-spring-swagger
Not sure why it his the case, but I also needed to add a web mvc configurer. I do use a requestmapping at the root of my controller to add
/api
everywhere. Anyway there is the kotlin + spring 5 version:It’s got resolve I have to configure changes in jersey file with annotation @Application Path
On 30-Mar-2018 8:56 PM, “Dilip Krishnan” notifications@github.com wrote:
What issue are you facing @aditi-goel https://github.com/aditi-goel? Are you seeing a 404 error? Yes different modules should work.
Also take a look at the demos https://github.com/springfox/springfox-demos project.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/springfox/springfox/issues/2037#issuecomment-377549368, or mute the thread https://github.com/notifications/unsubscribe-auth/AYmDcMWeBVZyc2eh69PGhGhuUYVD_eeFks5tjk60gaJpZM4PX4K8 .
@oaoit solution worked for me after 2 days of hustling. Many thanks!
I had the same setup as silentsnooc above, spring boot 1.5.9, swagger2 and swagger-ui 2.7.0. It did not map the /swagger-ui.html endpoint for me until I added the WebMvcConfig as noted above. One small change though,
.addResourceHandler("/swagger-ui.html")
The code above did not have the /.
Had the same issue, but nothing above helped. Started to wonder if it was a problem with the version 2.7.0. I had also followed this tutorial attempted to adapt it to gradle adding this to build.gradle:
compile group: ‘io.springfox’, name: ‘springfox-swagger-ui’, version: ‘2.7.0’
It seems this was horribly wrong.
While looking at another project of ours I found that we used the following instead for 2.4.0:
compile “io.springfox:springfox-swagger2:${swaggerVersion}” compile “io.springfox:springfox-swagger-ui:${swaggerVersion}” compile “io.springfox:springfox-bean-validators:${swaggerVersion}”
It solved my problem with 2.4.0 so I tried it with 2.7.0 and it also worked. Perhaps, if you are having this problem as a gradle project, this might solve your issue too.
Good luck!
@silentsnooc it is very likely that spring security is interfering with your web jar being visible
@denis111 Any idea what you did?
I’ve been following this tutorial. I added the dependencies
and created the configuration:
from the logs I see that the swagger endpoints are there:
but like others, I’m getting a 404 when accessing
http://localhost:8080/spring-security-rest/api/swagger-ui.html
.@dilipkrish I don’t have to do addResourceHandlers manually, I just wanted swagger-ui to work and I tried this workaround suggested in this topic. Anyway, today I’ve done something(maybe updates something) and now it works without addResourceHandlers. Thanks everybody for support.