问题:

Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
解决办法:
让你的Application 启动类继承SpringBootServletInitializer,然后scanBasePackages包范围内都扫描,因为你可能还依赖了子项目,子项目中的配置信息也要扫描进来。
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class, scanBasePackages = "com.sx.*")
public class WangDianApplication extends SpringBootServletInitializer {
public static void main(String args[]) {
SpringApplication.run(WangDianApplication.class, args);
}
}
本文解决了在使用Spring Boot框架时遇到的Swagger无法自动推断BaseUrl的问题,通过让启动类继承SpringBootServletInitializer并调整scanBasePackages配置,确保所有依赖的子项目配置都能被正确扫描。
7953





