spring-boot-starter-swagger 1.3.0.RELEASE:新增对JSR-303的支持和host的配置
2017-09-02 23:03
399 查看
版本基础
Spring Boot:1.5.xSwagger:2.7.x
如何使用
在该项目的帮助下,我们的Spring Boot可以轻松的引入swagger2,主需要做下面两个步骤:在
pom.xml中引入依赖:
<dependency> <groupId>com.didispace</groupId> <artifactId>spring-boot-starter-swagger</artifactId> <version>1.3.0.RELEASE</version> </dependency>
在应用主类中增加
@EnableSwagger2Doc注解
@EnableSwagger2Doc @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
参数配置
配置内容参考如下:配置示例
swagger.title=spring-boot-starter-swagger swagger.description=Starter for swagger 2.x swagger.version=1.3.0.RELEASE swagger.license=Apache License, Version 2.0 swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger swagger.contact.name=didi swagger.contact.url=http://blog.didispace.com swagger.contact.email=dyc87112@qq.com swagger.base-package=com.didispace swagger.base-path=/** swagger.exclude-path=/error, /ops/**
配置说明
默认配置- swagger.title=标题 - swagger.description=描述 - swagger.version=版本 - swagger.license=许可证 - swagger.licenseUrl=许可证URL - swagger.termsOfServiceUrl=服务条款URL - swagger.contact.name=维护人 - swagger.contact.url=维护人URL - swagger.contact.email=维护人email - swagger.base-package=swagger扫描的基础包,默认:全扫描 - swagger.base-path=需要处理的基础URL规则,默认:/** - swagger.exclude-path=需要排除的URL规则,默认:空 - swagger.host=文档的host信息,默认:空
host属性从1.3.0.RELEASE开始支持
Path规则说明
swagger.base-path和
swagger.exclude-path使用ANT规则配置。
我们可以使用
swagger.base-path来指定所有需要生成文档的请求路径基础规则,然后再利用
swagger.exclude-path来剔除部分我们不需要的。
比如,通常我们可以这样设置:
management.context-path=/ops swagger.base-path=/** swagger.exclude-path=/ops/**, /error
上面的设置将解析所有除了
/ops/开始以及spring boot自带
/error请求路径。
其中,
exclude-path可以配合
management.context-path=/ops设置的spring boot actuator的context-path来排除所有监控端点。
分组配置
当我们一个项目的API非常多的时候,我们希望对API文档实现分组。从1.2.0.RELEASE开始,将支持分组配置功能。具体配置内容如下:
- swagger.docket.<name>.title=标题 - swagger.docket.<name>.description=描述 - swagger.docket.<name>.version=版本 - swagger.docket.<name>.license=许可证 - swagger.docket.<name>.licenseUrl=许可证URL - swagger.docket.<name>.termsOfServiceUrl=服务条款URL - swagger.docket.<name>.contact.name=维护人 - swagger.docket.<name>.contact.url=维护人URL - swagger.docket.<name>.contact.email=维护人email - swagger.docket.<name>.base-package=swagger扫描的基础包,默认:全扫描 - swagger.docket.<name>.base-path=需要处理的基础URL规则,默认:/** - swagger.docket.<name>.exclude-path=需要排除的URL规则,默认:空
说明:
<name>为swagger文档的分组名称,同一个项目中可以配置多个分组,用来划分不同的API文档。
分组配置示例
swagger.docket.aaa.title=group-a swagger.docket.aaa.description=Starter for swagger 2.x swagger.docket.aaa.version=1.3.0.RELEASE swagger.docket.aaa.termsOfServiceUrl=https://gitee.com/didispace/spring-boot-starter-swagger swagger.docket.aaa.contact.name=zhaiyongchao swagger.docket.aaa.contact.url=http://spring4all.com/ swagger.docket.aaa.contact.email=didi@potatomato.club swagger.docket.aaa.excludePath=/ops/** swagger.docket.bbb.title=group-bbb swagger.docket.bbb.basePackage=com.yonghui
说明:默认配置与分组配置可以一起使用。在分组配置中没有配置的内容将使用默认配置替代,所以默认配置可以作为分组配置公共部分属性的配置。
JSR-303校验注解支持
JSR-303校验注解的展示,如下图所示:目前共支持以下几个注解:
@NotNull
@Max、
@Min
@Size @Pattern
本文转载至 程序猿DD-翟永超
相关文章推荐
- spring-boot-starter-swagger 1.2.0.RELEASE:新增分组配置功能
- spring-boot-starter-swagger 1.2.0.RELEASE:新增分组配置功能
- maven <artifactId>spring-boot-starter-parent</artifactId>里配置的版本<version>1.3.0.M1</version>和<version>1.5.6.RELEASE</version>有什么区别
- spring-boot-starter-logging logback配置之<configuration><logger>标签详解
- Swagger配置(SpringMVC、SpringBoot)
- Spring Boot全局支持CORS(跨源请求)的配置方法
- spring-boot-starter-velocity配置异常
- Spring boot 添加jsp支持配置
- Springboot 使用 JSR 303 对 Controller 控制层校验及 Service 服务层 AOP 校验 使用消息资源文件对消息国际化
- Spring Boot 支持多种外部配置方式
- <springBoot>(二)(入门篇)Eclipse中右击新增没有Spring Starter Project选项处理办法
- 使用SwaggerSpringBootStarter展示web项目api接口
- springboot+swaggerui配置
- spring boot开发遇到坑之spring-boot-starter-web配置文件使用教程
- 聊聊spring-boot-starter-data-redis的配置变更
- SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active(转)
- spring-boot-starter-redis配置详解
- 使用spring-boot-starter-data-jpa 怎么配置使运行时输出SQL语句
- SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active
- springboot swagger starter