springfox: Can't find Swagger UI endpoint
Please take the time to search the repository, if your question has already been asked or answered.
- What version of the library are you using? 2.8.0 With spring boot.
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
What kind of issue is this?
- Question. Is this a question about how to do a certain thing?
Hello,
I’m sure this is a stupid question but I’ve followed the steps on http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api to get the swagger / swagger ui to work.
My docket config looks as follows:
@Bean
public Docket mainConfig() {
return new Docket(DocumentationType.SWAGGER_2)
.select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/swagger")
.directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class);
}
With this I can go to /v2/api-docs
to see the json version. However I can’t find the UI endpoint.
When going to http://localhost:8080/swagger-resources/
I only see:
[
{
"name": "default",
"url": "/v2/api-docs",
"swaggerVersion": "2.0",
"location": "/v2/api-docs"
}
]
I’ve tried:
- http://localhost:8080/swagger-ui.html
- http://localhost:8080/v2/api/swagger-ui.html
- http://localhost:8080/swagger-resources/swagger-ui.html
- http://localhost:8080/api/swagger-ui.html
To no avail.
Thank you!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 69 (16 by maintainers)
Commits related to this issue
- Downgraded springfox version due to https://github.com/springfox/springfox/issues/2396 — committed to mfvanek/spring5-mvc-with-embedded-tomcat by deleted user 4 years ago
- Added Swagger UI (#11) * Added Swagger UI (but not working) * Downgraded springfox version due to https://github.com/springfox/springfox/issues/2396 * Restored 3.0.0 version with fixes in confi... — committed to mfvanek/spring5-mvc-with-embedded-tomcat by mfvanek 4 years ago
I have encountered this problem before and the problem was in the below line in application.properties spring.resources.add-mappings=false
remove it or change it’s value to true
Hello @nWidart,
I was facing the same issue, but I’ve figured out what was happening in my case…
Although I see you have fixed the problem already, for those whom this suggestion hasn’t worked, if you’re using @EnableMvc in any java config file, remove it. I’ve not quite believed at the beginning, but it has worked.
Give it a try…
Regards,
Luciano Daher.
Hi @dilipkrish , I’m facing the same 404 issue. The
/v2/api-docs
works fine, and the response tohttp://localhost:8080/swagger-resources/
looks exactly same as @nWidart 's description. I don’t know if it’s resulted from multiple modules with spring boot in my scenario, because the log showsIt work fine now. I found there ware 2 WebMvcConfigurationSupport in the project… @nWidart
Hello,
Problem is not fixed for me. I don’t have this
@EnableMvc
personally.It should be available @
http://localhost:8080/swagger-ui.html
. If you don’t see it, are you seeing a 404 error or are you seeing a 401 (unauthorized)? Since its based on the tutorial, is that repository shareable?Hello,
I’m getting a 404 on that path.
Same error with version
3.0.0
. I downgraded to2.9.2
and it worked.@rs-renato Please try 2.9.2. But I sincerely doubt it will fix it.
Are you seeing
unable to infer base host
? It is a very environment specific problem. Some of the common reasons for those are@EnableWebMvc
annotation or implementingWebMvcConfigurationSupport
, then you need to configure your swagger-ui on your own (add resource handlers). The web jar will not be auto configured for you.What would help me figure out the problem easier is one of the following
Hope that helps.
I would like to share some tips: if your project enabled with @EnableWebMvc, that means your swagger resource won’t be able to load into META-INF/resources. In order to load it, in case that project is really need annotations @EnableWebMvc for other reason, you need to override resource handlers and add the following lines below:
springfox-swagger-ui 2.9.2, is not working with AWS ALB. It is trying to redirect on the /api/null/swagger-resources/configuration/ui when trying to access /swagger-resources/configuration/ui. not sure why null is being added.
At local it works OK though with localhost.
This is the config I have …/swagger-resources/configuration/ui" is being redirected to /api/null/swagger-resources/configuration/ui.
/**
/**
I can second @luismh - same issue and versions - removed
@EnableWebMvc
and works fine.Actually, come to think of it, removing
@EnableWebMvc
fixes quite a few things!Facing the same issue here with 2.8.0, 2.7.0 works well
I’ve faced with the same issue on 3.0.0 and 2.10.5 - swagger-ui.html returns 404. On 2.9.2 it works https://github.com/mfvanek/spring5-mvc-with-embedded-tomcat
Update: I’ve restored 3.0.0 version with fixes according to official documentation. Everything is OK, but the documentation is slightly confusing and misleading
Just my 5 cents… i compiled my project with Java 11 and it gave me same issue. I downgraded to version Jave 8 and it works without further changes to above.
With having trouble in Java 11, the entire Project technically hasn’t built, so it wasn’t even creating the db tables (hibernate), but it showed as running in tomcat.
I had the same issue, just removed
@EnableWebMvc
and works! Thanks.i solved the problem, the reason is I have an endpoint from spring mvc, which conflict with /swagger-ui.html
https://stackoverflow.com/questions/49152204/swagger-ui-html-400-bad-request
I’m using spring boot 2.0.3 and swagger 2.9.2.
swagger-ui
also give me the errorunable to infer base host
. Through debug the springfox.js of 2.8.0, it turns out thatswagger-resources
request expect array but get a object by wrapped@RestControllerAdvice
. So the js promtunable to infer base host
. After remove the wrap behavior of swagger, swagger-ui works.This is what just helped me. I was migrating an old project and still had this. Thanks a million!!
This worked for me. Now I am finding the right configuration.
Are there docs or any starting places for doing this?
I dont understand the problem you’re having
I have:
Suggest to move to SpringDoc
Den 05-12-2022 kl. 00:06 skrev Yahm:
Following the example from @siengsotheara from above. This is the Java version.
If you have @EnableWebMvc, WebMvcConfigurer or WebMvcConfigurationSupport somewhere in your project, this should fix the problem.
I can now access the UI on this path:
*base*/swagger-ui/index.html
Greetings from Munich
Had the same issue of the swagger-ui no longer showing up. Took me a while to find out where the issue was. Turned out I had a /{id} mapped to my general root which then caused /swagger-ui.html stating there was a missing ‘id’ parameter
I had the same problem. I didn’t have the swagger-ui dependency on my gradle dependencies. Added the swagger-ui dependency and it worked. Ended up with this:
https://github.com/oeresundsgruppen/swaggerTest - updated and Tomcat deployment works now. dispatcher needed setup. Months of debugging over. Thanks @dilipkrish - hope others can re-use this.
Like @dilipkrish said:
i removed the extends and its works like a charm
Thank you
In that case perhaps one of your endpoints is pointing has a request mapping of
/{something}
Have you include the
springfox-swagger-ui
dependency?