Swagger浏览器访问报错 Unable to infer base url. This is common when using dynamic servlet registrat...

通过浏览器访问Swagger报错

Swagger浏览器访问报错 Unable to infer base url. This is common when using dynamic servlet registrat..._第1张图片

后来通过以下方法解决了

解决方法:主启动类加上@ComponentScan("swagger配置类所在包")以保证配置类被扫描到

找到swagger配置类所在的包路径

Swagger浏览器访问报错 Unable to infer base url. This is common when using dynamic servlet registrat..._第2张图片

@SpringBootApplication()
@ComponentScan("com.demo.ceshi.config")//根据自己需要填写包名
public class ApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }

}

 

 

备注:如果还是不行,检查本地项目是否有拦截器,加上以下代码即可。

Swagger浏览器访问报错 Unable to infer base url. This is common when using dynamic servlet registrat..._第3张图片

//排除swagger拦截
registry.addInterceptor(loginInterceptor)
        .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");

你可能感兴趣的:(研发管理)