最终效果图:
2个模块demo demo2对应在swaggerui上有2个不同的分组信息
代码实现方式:
package org.springblade.common.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * 功能描述:SwaggerConfig 分组配置 * @author * @date 2019年7月3日08:40:41 */ @Configuration @EnableSwagger2 public class SwaggerConfig { /** * 创建API应用 * apiInfo() 增加API相关信息 * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现, * 本例采用指定扫描的包路径来定义指定要建立API的目录。 * * @return */ @Bean public Docket restApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("分组-DEMO-1") .apiInfo(apiInfo("分组-DEMO-1", "1.0")) .useDefaultResponseMessages(true) .forCodeGeneration(false) .select() //这个配置是用来指定我们的接口层的位置,大家可以根据你自己项目的实际情况来进行修改 .apis(RequestHandlerSelectors.basePackage("org.springblade.demo.controller")) .paths(PathSelectors.any()) .build(); } @Bean public Docket restApi2() { return new Docket(DocumentationType.SWAGGER_2) .groupName("分组-DEMO-2") .apiInfo(apiInfo("分组-DEMO-2", "1.0")) .useDefaultResponseMessages(true) .forCodeGeneration(false) .select() .apis(RequestHandlerSelectors.basePackage("org.springblade.demo2.controller")) .paths(PathSelectors.any()) .build(); } /** * 创建该API的基本信息(这些基本信息会展现在文档页面中) * @return */ private ApiInfo apiInfo(String title, String version) { return new ApiInfoBuilder() .title(title) .description("自定义分组接口") .termsOfServiceUrl("服务URL") .contact(new Contact("DKYI", "localhost:3807/服务/", "@163.com")) .version(version) .build(); } }
讨论(0)
官方新品
- 热议问题
-
bladex微服务版本和saber3怎整合websocket,有没有案例呀
1
-
nacos多个实例数会很卡,前端请求一直转圈圈什么原因呢
1
-
请问OTA升级功能有无计划推出的时间?
1
-
前端页面登录,却报用户或密码错误
1
-
bladex依赖拉不下来,版本 2.9.1.RELEASE
1
-
bladex-boot项目导入2.9.0包报错
2
-
Bladex 3.4.0如何接入登录
1
-
Bladex用户信息扩展
1
-
从bladex切换到boot版本 路由不知道为什么总是报错
1
-
登入提示 java.lang.ClassNotFoundException: org.springblade.system.entity.Tenant,代码都是最新的
1
扫一扫访问 Blade技术社区 移动端