有什么方法可以阻止springfox昂首阔步地扫描模型类吗? [英] Is there a way I can stop springfox swagger from scanning the model classes?

查看:276
本文介绍了有什么方法可以阻止springfox昂首阔步地扫描模型类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Springfox Swagger通过Java配置记录我的spring boot应用程序.我的API在整个扫描过程中的启动时间约为75秒(如果没有Springfox,最初是20秒).我目前只需要控制器信息,而无需任何型号信息.有没有一种方法可以从启动过程中排除模型扫描,以使我的API更快启动?还有其他方法可以使其更快吗?我正在使用swagger 1.2

I'm currently using Springfox Swagger to document my spring boot application with a Java config. My API starts in about 75 seconds, (it was originally 20 secs without Springfox) with the whole scanning process. I currently just need the controller information without any model info. Is there a way I can exclude model scanning from the startup process in order to make my API start faster? And are there any other ways to make it faster? I'm using swagger 1.2

推荐答案

有一种方法可以防止Sprinfox框架生成Swagger模型或指定忽略类型的参数信息.您必须使用SwaggerSpringMvcPluginDocket类中的方法ignoredParameterTypes使其知道要忽略的类型.

There is a way to prevent Sprinfox framework from generating a Swagger model or parameter information of specified ignored types. You have to use the method ignoredParameterTypes in SwaggerSpringMvcPlugin or Docket class to let it know the types to be ignored.

这里是带有忽略类型的Swagger 1 Java配置示例.肯定会影响我的应用程序启动时间.

Here is an example of Swagger 1 Java configuration with ignored types. It definitely had an impact on my application startup time.

@Configuration
@EnableSwagger
public class SwaggerConfiguration {

    @Autowired
    private SpringSwaggerConfig springSwaggerConfig;

    @Bean
    public SwaggerSpringMvcPlugin api() {
        Class[] clazz = {MyClassA.class, MyClassB.class};

        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
                .apiInfo(apiInfo())
                ...
                .ignoredParameterTypes(clazz);
    }

     private ApiInfo apiInfo() {
         ...
     }
}

Swagger 2示例

这是带有忽略类型的Swagger 2 Java配置示例,

Swagger 2 Example

Here is an example of Swagger 2 Java configuration with ignored types,

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket api() {
        Class[] clazz = {MyClassA.class, MyClassB.class};

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("my-group")
                .select()
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .ignoredParameterTypes(clazz);
    }

     private ApiInfo apiInfo() {
         ...
     }
}

这篇关于有什么方法可以阻止springfox昂首阔步地扫描模型类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆