【问题标题】:Spring boot 2.0 with swagger ui not working properly带有 swagger ui 的 Spring Boot 2.0 无法正常工作
【发布时间】:2018-03-31 10:17:12
【问题描述】:

我正在尝试将 Spring Boot 2.0 与 swagger 集成但未显示端点。当我在网络选项卡上查看开发人员控制台时,它说我找不到“http://localhost:8080/swagger-resources/configuration/ui”并返回 404。

【问题讨论】:

  • 您正在使用哪个招摇实现? .. 尝试将 url 打为localhost:8080/swagger-ui.html
  • 请添加更多信息:您是否使用 springfox,您是否有现有的控制器或将使用 codegen,您的 SpringBoot 是否配置了 Oauth 或其他安全性?
  • 如果您还可以发布您的 application.properties 的样子。我遇到了同样的问题,在我指定 spring.resources.static-locations[0]=file:src/main/resources/static/spring.resources.static-locations[0]=file:src/main/resources/static/ b>spring.resources.static-locations[1]=classpath:/static/

标签: spring-boot swagger


【解决方案1】:

我们通过为 swagger 添加资源处理程序解决了这个问题:

例子:

@Configuration
public class MvcConfiguration extends WebMvcConfigurationSupport {
    @Value("${spring.application.name}")
    private String applicationName;

    //...irrelevant code here

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}

【讨论】:

    【解决方案2】:

    如果您在项目中的任何位置有 @EnableWebMvc 或 @WebMvcConfigurationSupport 注释,则删除它们或添加自定义资源处理程序以配置 swagger-ui。

    以下是一些常见的解决方案: https://github.com/springfox/springfox/issues/2396#issuecomment-402150402

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      • 2018-06-01
      • 2021-02-03
      • 1970-01-01
      • 2017-05-18
      • 2020-02-22
      相关资源
      最近更新 更多