一尘不染

Spring Boot和Swagger 2 UI和自定义请求映射处理程序映射-映射问题

spring-boot

我有自己的RequestMappingHandlerMapping,并且正在使用springfox-swagger-
ui。添加自定义映射后,我无法在http:// localhost:8080 / swagger-
ui.html
上实现swagger ui 。有任何想法吗?

这是我的配置。

    @Configuration
       public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Override
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        return new ApiVersionRequestMappingHandlerMapping("v");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
          .addResourceHandler("/webjars/**")
          .addResourceLocations("(META-INF/resources/webjars");
    }
}

这是我的pom.xml:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

阅读 913

收藏
2020-05-30

共1个答案

一尘不染

我终于找到了!正确的配置是这样的:

@Configuration
public class VersioningMappingHandlerConfig {

    @Bean
    public ApiVersionRequestMappingHandlerMapping customMappingHandlerMapping() {
        ApiVersionRequestMappingHandlerMapping handler = new ApiVersionRequestMappingHandlerMapping("v", 1, 1);
        handler.setOrder(-1);
        return handler;
    }

}

注意:没有extends WebMvcConfigurationSupport,bean名称是customMappingHandlerMapping

2020-05-30