Springfox Swagger可以从Spring @ComponentScan排除的软件包中扫描控制器吗?

时间:2018-07-19 18:36:59

标签: java spring swagger springfox

在我的Spring MVC应用程序中,我使用的是Springfox版本:2.5.0和Spring版本:4.3.3.RELEASE,请考虑以下配置:

package com.example.api.configuration;

// import statements

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.example.api", excludeFilters = @Filter(type = FilterType.REGEX, pattern = "com\\.example\\.api\\.mockcontroller\\..*"))
public class SpringMvcConfiguration extends WebMvcConfigurerAdapter {

// class code goes here

}

我在@Controllercom.example.api.controller包中有用com.example.api.mockcontroller注释的类(控制器),其中我不希望Spring扫描com.example.api.mockcontroller中的类(控制器)包,所以我使用excludeFilters将它们排除在扫描范围之外。

但是我希望com.example.api.controllercom.example.api.mockcontroller包中的类(控制器)由Springfox昂首阔步拾取。

我的Swagger配置文件如下:

package com.example.api.configuration;

// import statements

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage(("com.example.api")))
        .paths(PathSelectors.any())
        .build();
    }
}

Springfox招摇只是从com.example.api.controller包中挑选控制器。

0 个答案:

没有答案