No mappings found for swagger-resources / configuration / ui

I am trying to configure swagger ui in an application to boot without spring. I did the following. 1. Added the following dependencies

<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

@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. The following displays are added:

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

I can access the following URL

    /v2/api-docs
    /swagger-resources

But when loading swagger-ui.html, the user interface loads and the following error appears on the server enter image description here

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

Can anyone help?

+4
source share
2 answers

I am using Swagger version 2.3.1 in my room. I wonder why you have different versions for artifacts springfox-swagger2and springfox-swagger-ui?

The My SwaggerConfig class looks like this. No properties:

@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

+2

springfox-swagger2 springfox-swagger-ui . , 2.5.0 2.6.1, . , 2.6.1, - 2.4.0, ui . , , , .

0

Source: https://habr.com/ru/post/1650034/


All Articles