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

标签 java spring documentation swagger springfox

<分区>

我正在尝试在非 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。添加了 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. 添加了以下映射:

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

我可以访问以下网址

    /v2/api-docs
    /swagger-resources

但是在加载 swagger-ui.html 时 UI 被加载并且在服务器上出现以下错误 enter image description here

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

有人可以帮忙吗?

最佳答案

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

我的 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/*.*")
                );
    }
}

没有适合我的配置或资源。

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

关于java - 找不到 swagger-resources/configuration/ui 的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744115/

相关文章:

java - 小程序单例spring beans问题

java - spring mvc - 检查您所在页面并更改菜单项样式的最简单方法

asp.net-web-api - ASP.Net Web API帮助页面区域返回空输出

java - 如何从一个 servlet 文件调用另一个 servlet 文件?

java.lang.NoClassDefFoundError : Could not initialize class org. jose4j.jwa.AlgorithmFactoryFactory JsonWebSignature getCompactSerialization 错误

java - 使用 Mule ESB 解析 MySQL 存储过程结果集

java - 如何告诉 hibernate validator 仅验证一个注释?

java - JSONDOC 创建显示异常

objective-c - 在哪里可以获得有关 Mac OS X CoreWLAN 的完整引用?

java - 如何使用 Velocity 脚本的 SortTool 对字符串列表进行排序?