Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Springfox Swagger 2 – Method paths(regex ("string")) does not work

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();
    }

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading