You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway #2191
Make sure that all query are ok in developer console, I have the same issue, some of my queries return 403.
In my project, Swagger is behind basic auth (to prevent swagger to be public), but /swagger-resources/** routes are not called with Authorization header since I updated to Springfox 2.8.0
The workaround is to make this route public : .antMatchers("/swagger-resources/**").permitAll()
Reacted by Ludovic Dussart, Michael Coughlin, Barna Adrian, Richard Danby, Artem Kudria, Rodrigo Sene, kid304, zahid-enquizit, stavrogin, john and 6 more
Does this issue have been figured out?? Once i upgraded to 2.8.0 from 2.6.1, the swagger ui started showing the error "Unable to infer base url".
When I look at debug logs, i do see this line.
{"category":"org.springframework.boot.web.filter.OrderedRequestContextFilter","severity":"DEBUG","text":"Bound request context to thread: Request(GET //localhost:10780/my-service/api/null/null/swagger-resources)@5689340d"},"v":"1"}
Why the base url for the swagger-resources are messed up - no idea! I tried debugging, and when i step in I do see the context path of my application is right, which is /my-service.
But this removes all security of those endpoints. An other solution is setting the Authorization header with the basic authentication.
But what I think should happen is the basic authentication pop-up is shown before the "Unable to infer base url" pop-up
Reacted by Gustavo Antonio Correa Caja, guohezuzi, Qiang Zeng, Carlos Daniel and VinayKumar
Hey guys, in my case it was a ResponseBodyAdvice that changed the response body of /v2/api-docs endpoint. I fixed the advice and the ui was rendered as expected.
Sorry to open this issue but I am facing the same issue just after changing the static resource path from spring.mvc.static-path-pattern=/** to spring.mvc.static-path-pattern=/app-resources/**.
Nothing related to Spring Security configuration, but I had the same issue and I fixed it, by changing this :
@RestControllerAdvice
public class MyResponseBodyAdvice implements ResponseBodyAdvice<ResponseWrapper> {
}
to
@RestControllerAdvice("my.super.package")
public class MyResponseBodyAdvice implements ResponseBodyAdvice<ResponseWrapper> {
}
Without adding restriction on base package to scan, in annotation @RestControllerAdvice, I guess it scans also all the package dependencies, and tries to cast all the ResponseBody to the defined type (in my case ResponseWrapper).
I'm running Spring Boot 2.0.2.RELEASE and Swagger 2.8.0; Springfox update to 2.9.0 didn't fix my problem.
I was stuck for a day with this issue. My issue was incorrect port configuration. Check your application.yml/application.properties file for port configuration. There I had mistakenly added both
server.port , management.server.port with different values 🤣 .
I have resolve the issue by downgrading the Swagger version and Implementing swagger in Spring MVC. But facing another issue with @EnableSwagger2. If is use this annotation i am getting error as given below -
Caused by: java.lang.NoSuchMethodException: springfox.documentation.spring.web.SpringfoxWebMvcConfiguration$$EnhancerBySpringCGLIB$$f6a2d0cd.jsonSerializer()
Has anyone faced this error before? Could any suggest the solution for this?
Activity
cpoissonnier commentedon Jan 17, 2018
Make sure that all query are ok in developer console, I have the same issue, some of my queries return 403.
In my project, Swagger is behind basic auth (to prevent swagger to be public), but
/swagger-resources/**routes are not called withAuthorizationheader since I updated to Springfox 2.8.0The workaround is to make this route public :
.antMatchers("/swagger-resources/**").permitAll()goodlifeinc commentedon Jan 17, 2018
Well I am using Swagger 2.7.0 and this fix doesn't help.
Here is my security setup. Actuator endpoints are behind basicAuthentication.
Stangest thing is same config in another project with same dependencies works fine.
EDIT
With a strange combination between @configuration and @EnableSwagger2 on SwaggerDocumentationConfig class, seems to have solved my issue.
kasecato commentedon Jan 18, 2018
@cpoissonnier An
Authorizationheader will be added on the same-origin by #2189.evser commentedon Jan 20, 2018
We should NOT disable security checks for swagger resources - as it also have sensitive data that should NOT be shown to any unknown user
evser commentedon Jan 20, 2018
BTW, here are my settings (I use cookies-based auth in my browser):
And Docket:
Hronom commentedon Jan 26, 2018
Same here what the status of pull request?
My application is protected by basic auth using api gateway.
dilipkrish commentedon Jan 30, 2018
@evser thanks for sharing your configuration. You are absolutely correct about not unauthenticated users access to specification resources
crazy-airhead commentedon Feb 12, 2018
Maybe Help. I found that the Springboot Application Class need to add @EnableSwagger2 annotation.
seetharamani commentedon Mar 9, 2018
Does this issue have been figured out?? Once i upgraded to 2.8.0 from 2.6.1, the swagger ui started showing the error "Unable to infer base url".
When I look at debug logs, i do see this line.
{"category":"org.springframework.boot.web.filter.OrderedRequestContextFilter","severity":"DEBUG","text":"Bound request context to thread: Request(GET //localhost:10780/my-service/api/null/null/swagger-resources)@5689340d"},"v":"1"}Why the base url for the swagger-resources are messed up - no idea! I tried debugging, and when i step in I do see the context path of my application is right, which is /my-service.
Any help is appreciated.
dilipkrish commentedon Mar 10, 2018
Not sure. Would be great if you could share your repository
AlexRosier commentedon Mar 16, 2018
I have the same issue using spring security with basic authentication. What avoided the issues is adding
But this removes all security of those endpoints. An other solution is setting the Authorization header with the basic authentication.
But what I think should happen is the basic authentication pop-up is shown before the "Unable to infer base url" pop-up
dilipkrish commentedon Mar 17, 2018
@AlexRosier I think you need to protect the swagger resources as well starting from
swagger-ui18 remaining items
luksrn commentedon Dec 6, 2018
Hey guys, in my case it was a ResponseBodyAdvice that changed the response body of /v2/api-docs endpoint. I fixed the advice and the ui was rendered as expected.
dilipkrish commentedon Dec 17, 2018
@luksrn thanks for clarifying!
akuma8 commentedon Jan 13, 2019
Sorry to open this issue but I am facing the same issue just after changing the static resource path from

spring.mvc.static-path-pattern=/**tospring.mvc.static-path-pattern=/app-resources/**.MehmetMelik commentedon Jan 16, 2019
Clearing the browser cache in chrome fixed the issue. This may sound weird but this is what solved the problem in my case.
sidhjhawar commentedon Jun 28, 2019
Yes, I just used incognito mode to open the swagger-ui and it worked fine.
rakesh415 commentedon Aug 1, 2019
It worked for me after adding above lines. But what if I need some security to my applications.
MohSalah90 commentedon Aug 3, 2019
This solved my issue, thank you for sharing Bro.
hacki11 commentedon Aug 30, 2019
this was helpful for me, using my own swagger.json with springfox-swagger-ui:
indrabasak/springfox-ui-from-json-example#2
JakeWoki commentedon Jul 5, 2021
@evser
using Spring Security,how to add login/logout document?
MurilloNacfur commentedon Aug 6, 2021
Here it's worked : http://localhost:8080/swagger-ui/index.html
hasitha3rd commentedon Jan 5, 2022
I was stuck for a day with this issue. My issue was incorrect port configuration. Check your application.yml/application.properties file for port configuration. There I had mistakenly added both
server.port , management.server.port with different values 🤣 .
miladmofidi commentedon Apr 26, 2022
I have the same issue, when I open swagger UI URL: http://192.168.32.241:31650/swagger-ui.html , appear this error I read the comments but I could not solve my issue.
my SwaggerConfig.java is:
And this is my SecurityConfig.java :
Updated documenation with example of how to secure swagger-ui
VinayakKulkarniTR commentedon Mar 28, 2024
I have resolve the issue by downgrading the Swagger version and Implementing swagger in Spring MVC. But facing another issue with @EnableSwagger2. If is use this annotation i am getting error as given below -
Caused by: java.lang.NoSuchMethodException: springfox.documentation.spring.web.SpringfoxWebMvcConfiguration$$EnhancerBySpringCGLIB$$f6a2d0cd.jsonSerializer()
Has anyone faced this error before? Could any suggest the solution for this?
Greko2017 commentedon Aug 14, 2025
This solved my issue thanks