Search code examples
javagradleswaggerspringfox

No mapping found for / GET / swagger


I am trying to configure swagger for a project but I receive an error infinite times:

o.s.web.servlet.PageNotFound             : No mapping for GET /project1/api/null/swagger-resources/configuration/ui" 
o.s.web.servlet.PageNotFound             : No mapping for GET /project1/api/null/swagger-resources/configuration/ui" 
o.s.web.servlet.PageNotFound             : No mapping for GET /project1/api/null/swagger-resources/configuration/ui" 
o.s.web.servlet.PageNotFound             : No mapping for GET /project1/api/null/swagger-resources/configuration/ui" 
................

I have a multi project layer. The structure is :

ProjectName

-- project1

  --setting.gradle

  --build.gradle

-- project2

  --setting.gradle

  --build.gradle

--setting.gradle

In each build.gradle I have this dependencies:

compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'

The SwaggerConfiguration class is :

@EnableSwagger2
@Configuration
public class SwaggerConfiguration {

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/");
    }
}

And also i have a WebConfigure class:

@Configuration
@EnableWebMvc
@Slf4j
public class WebConfigure extends WebMvcConfigurationSupport {
    @Bean
    public AuthorizationInterceptor requestInterceptor() {
        return new AuthorizationInterceptor();
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("Adding interceptor [{}]", AuthorizationInterceptor.class.getName());
        registry.addInterceptor(requestInterceptor());
    }

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

If I try to access http://localhost:8090/project1/api/swagger-ui.html I receive this error:

Swagger error


Solution

  • Remove "/api" from the server.servlet.context-path .

    Somehow the swagger is in conflict with that part.