本文介绍了弹簧靴 &Swagger 2 UI &自定义 requestmappinghandlermapping - 映射问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have own RequestMappingHandlerMapping and I am using springfox-swagger-ui. After adding my custom mapping, I am not able to achieve swagger ui at http://localhost:8080/swagger-ui.html.Any ideas?

这是我的配置.

    @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:

Here's my 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>

推荐答案

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

I finally find it!The right configuration is this:

@Configuration
public class VersioningMappingHandlerConfig {

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

}

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

Note: there is no extends WebMvcConfigurationSupport and bean name is customMappingHandlerMapping

这篇关于弹簧靴 &amp;Swagger 2 UI &amp;自定义 requestmappinghandlermapping - 映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:06