Home > Enterprise >  Springfox Swagger 2 - Method paths(regex ("string")) does not work
Springfox Swagger 2 - Method paths(regex ("string")) does not work

Time:05-17

so I'm writing a Docket, but when i call the paths method, there is the error "The method regex(String) is undefined for the type SwaggerConfig". My swagger dependencies all have the same version (3.0.0)

here is the code snippet I struggle with

package de.tut.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
public class SwaggerConfig {
    
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("de.tut"))
                .paths(regex("/rest.*"))
                .build();
    }

}

CodePudding user response:

You need to use

PathSelectors.regex("/rest.*")

with PathSelectors being

springfox.documentation.builders.PathSelectors

Just using regex assumes that you want to use a method of the class you are in, which is what the compiler error is complaining about.

  • Related