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

前端 未结 13 868
醉话见心
醉话见心 2020-12-10 11:01

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

相关标签:
13条回答
  • 2020-12-10 11:38

    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.

    0 讨论(0)
  • 2020-12-10 11:39

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

    @EnableSwagger2
    
    0 讨论(0)
  • 2020-12-10 11:42

    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-10 11:43

    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.

    0 讨论(0)
  • 2020-12-10 11:43

    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.

    0 讨论(0)
  • 2020-12-10 11:44

    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.

    0 讨论(0)
提交回复
热议问题