首页 > 解决方案 > springfox-swagger-3-0- 不适用于非启动 spring4 mvc 项目

问题描述

参考:突然 Springfox Swagger 3.0 无法与 spring webflux 一起使用

2.9.2 版运行良好。但是当我将它升级到 3.0.0 时它失败了。

我遇到了同样的问题,但区别只是......我没有使用弹簧靴。

我有 spring mvc4 项目并添加了 3.0.0 版本的 swagger2 ......但我无法查看 swagger-ui。

pom.xml

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

SwaggerConfig.java

@Configuration
@ComponentScan
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig extends WebMvcConfigurerAdapter {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/.*")).build().apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("TITLE").description("INFO").version("V1.0")
                .termsOfServiceUrl("http://terms-of-services.url").license("LICENSE")
                .licenseUrl("http://url-to-license.com").build();
    }

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

}

并尝试如下所示一路狂妄自大。

localhost:8080/swagger-ui/index.html
localhost:8080/swagger-ui.html
localhost:8080/swagger-ui/

所有这些都不起作用.. :(

标签: spring-mvcswagger-uiswagger-2.0

解决方案


推荐阅读