How to change Swagger-ui URL prefix?

前端 未结 1 1651
别那么骄傲
别那么骄傲 2020-12-09 14:13

I am using Springfox Swagger2 with Spring boot 1.5.9.

I can access swagger UI on this link.

http://localhost:8090/swagger-ui.html

How can I change it

1条回答
  •  时光说笑
    2020-12-09 14:41

    Try this configuration class.

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig extends WebMvcConfigurationSupport {
    
      @Bean
      public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select().apis(RequestHandlerSelectors.basePackage(""my.favorite.package""))
                            .paths(regex(PathSelectors.any()))
            .build();
    
      }
    
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs").setKeepQueryParams(true);
        registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
        registry.addRedirectViewController("/documentation/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
        registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
      }
    
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/documentation/**").addResourceLocations("classpath:/META-INF/resources/");
      }
    
    
    }
    

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