java 没有找到 swagger-resources/configuration/ui 的映射

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38744115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:42:52  来源:igfitidea点击:

No mapping found for swagger-resources/configuration/ui

javaspringdocumentationswaggerspringfox

提问by Ganesh

I am trying to configure swagger ui in non spring boot app. I have done following things. 1. Added Following dependencies

我正在尝试在非 Spring Boot 应用程序中配置 swagger ui。我做了以下事情。1. 新增以下依赖

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.1.2</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.5</version>
    </dependency>

2. Added Swagger Config class

2. 添加 Swagger 配置类

@Configuration
@EnableSwagger2
@EnableWebMvc
//@PropertySource("classpath:/swagger.properties")
public class SwaggerConfig {

@Bean
public Docket proposalApis(){
    return new Docket(DocumentationType.SWAGGER_2)
        .groupName("test")
        .select()
            .apis(RequestHandlerSelectors.basePackage("com.test.abc"))
        .paths(PathSelectors.regex("/test1.*"))
        .build()
        .apiInfo(testApiInfo());
}

private ApiInfo testApiInfo() {
    ApiInfo apiInfo = new ApiInfoBuilder().title("Test APIs").description("GET POST PUT methods are supported ").version("V1").build();
    return apiInfo;
}
}
  1. Added following mappings :

    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-    INF/resources/"/>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-    INF/resources/webjars/"/>
    
  1. 添加了以下映射:

    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-    INF/resources/"/>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-    INF/resources/webjars/"/>
    

I am able to access following url's

我可以访问以下网址

    /v2/api-docs
    /swagger-resources

But While loading swagger-ui.html UI gets loaded and on server getting following error enter image description here

但是在加载 swagger-ui.html UI 时加载并在服务器上出现以下错误 在此处输入图片说明

    No mapping found for /context/swagger-resources/configuration/ui in Dispatcher servlet

Can someone help?

有人可以帮忙吗?

采纳答案by duffymo

I'm using Swagger version 2.3.1 in my pom. I wonder why you have different versions for springfox-swagger2and springfox-swagger-uiartifacts?

我在我的 pom 中使用 Swagger 2.3.1 版。我想知道为什么你有不同的版本springfox-swagger2springfox-swagger-ui工件?

My SwaggerConfig class looks like this. No properties:

我的 SwaggerConfig 类看起来像这样。无属性:

@EnableSwagger2
@Configuration
public class SwaggerConfig {
    @Autowired
    private TypeResolver typeResolver;

    @Bean
    public Docket swaggerSpringMvcPlugin() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("FooBar")
                .select()
                //Ignores controllers annotated with @CustomIgnore
                .apis(any()) //Selection by RequestHandler
                        .paths(paths()) // and by paths
                        .build()
                        .apiInfo(apiInfo()
                        );
    }

    private ApiInfo apiInfo() {
        return new ApiInfo("FooBar",
                "A java server based on SpringBoot",
                "1.0.0",
                null,
                "author","","");
    }

    //Here is an example where we select any api that matches one of these paths
    private Predicate<String> paths() {
        return or(
                regex("/foobar/*.*")
                );
    }
}

No configuration or resources for me.

我没有配置或资源。

The page comes right up when I hit the URL http://localhost:8080/foobar/swagger-ui.html

当我点击 URL 时页面立即出现 http://localhost:8080/foobar/swagger-ui.html

回答by Stuti Verma

Different versioning of springfox-swagger2 and springfox-swagger-ui has been an issue. In some cases, like former of 2.5.0 and latter of 2.6.1 version, the integration works fine. But, if former is of 2.6.1 and latter is of 2.4.0, then the ui becomes incompatible. Hence, I suggest if both the dependencies are taken of same version by practice, then unexpected functioning of swagger can be reduced.

springfox-swagger2 和 springfox-swagger-ui 的不同版本一直是一个问题。在某些情况下,例如 2.5.0 的前者和 2.6.1 版本的后者,集成工作正常。但是,如果前者是 2.6.1,后者是 2.4.0,则 ui 变得不兼容。因此,我建议如果通过实践将两个依赖项都采用相同的版本,那么可以减少 swagger 的意外功能。