springboot整合swagger实现指定生成和多路径生成

项目需要整合swagger,我就尝试了一下,整理一下方便大家也有类似的需求.

第一步:***在springboot启动类上加上@EnableSwagger2***注解,如下图:

@SpringBootApplication
@MapperScan({
   
        "com.xxx.xxx.xxx.dao"
})
//添加这个注解
@EnableSwagger2
public class MccplatformApplication {
   

    public static void main(String[] args) {
   
        SpringApplication.run(MccplatformApplication.class, args);
    }

}

第二步:添加对应的配置类,需要调整一下,下面代码controller层的文件路径
常规的配置如下:

import com.google.common.base.Predicate;
import com.google.common.base.Optional;
import com.google.common.base.Function;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
   

    /**
     * 创建API应用
     * apiInfo() 增加API相关信息
     * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
     * 本例采用指定扫描的包路径来定义指定要建立API的目录。
     *
     * @return
     */
    //这边需要把生成接口文档的项目路径调整一下,改成你项目对应的contoller的实际路径,下面是我项目的路径经供参考
    @Bean
    public Docket createRestApi() {
   
        return new Docket(DocumentationType.SWAGGER_2)
                .
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值