Why does springfox-swagger2 UI tell me Unable to infer base url.
As far as I know, I am using a typical Swagger spring-boot configuration.
As you can
in my case i had this line in my WebSecurityConfig.java:
.antMatchers("swagger-ui.html").permitAll()
and when i added this one:
.antMatchers("/swagger-resources/**").permitAll()
my problem resolved.
I was able to resolve the issue by adding SpringBootApplication with annotation - as suggested by Mark :
@EnableSwagger2
For Spring 2 use @SpringBootApplication annotation and extends your class application from SpringBootServletInitializer then override the method SpringApplicationBuilder
@SpringBootApplication
public class TestApp extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TestApp.class);
}
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
}
I am using spring boot.
In my case I made mistake in package name. in my project the base package name is
org.liferayasif.documents
so my configuration file should be inside
org.liferayasif.documents.config
config -> u can give any name.
but by mistake I put in different package name give below
org.liferayasif.config
once I put the configuration file inside proper package name in my case
org.liferayasif.documents.config
then it worked properly.
I needed to add anonymous access to resources in Spring Security method: protected void configure(HttpSecurity http)
.antMatchers("/api/**", "/swagger-ui.html", "/webjars/**", "/v2/**", "/swagger-resources/**").anonymous()
And then it starts working.
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.