Why does springfox-swagger2 UI tell me "Unable to infer base url."

It turns out that the solution to my problem was to move the @EnableSwagger2 annotation into the main Configuration class, along with the Docket Bean.

I had created a separate class in a sub-package with the Docket Bean and I was expecting it to get scanned by Spring and load the bean. Perhaps I failed to annotate that docket class with @Component, or maybe the the problem was something else, but I got it working.


For me the problem was that Spring Security was not allowing access to some resources needed by swagger-ui. The solution was to allow anonymous access to the following paths:

  • /swagger-ui.html
  • /webjars/**
  • /v2/**
  • /swagger-resources/**

In my case it is fine that these resources can be accessed without authentication.


I was able to resolve the issue by adding SpringBootApplication with annotation - as suggested by Mark :

@EnableSwagger2