SpringBoot下swagger3.0的配置
1、swagger3.0依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
我的springboot版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/>
</parent>
2、swagger配置类
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.zystart.sys.controller"))
.paths(PathSelectors.any())
.build();
}
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Quartz定时任务")
.description("测试swagger配置定时任务")
// .termsOfServiceUrl("https://www.baidu.com/")
.version("1.0")
.build();
}
}
3、我的application.yml配置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
4、访问地址
http://localhost:port/swagger-ui/index.html
5、Swagger注解说明
注解 | 说明 |
---|---|
@Api | 修饰整个类,描述Controller的作用 |
@ApiOperation | 描述一个类的一个方法,或者说一个接口 |
@ApiParam | 单个参数描述 |
@ApiModel | 用对象来接收参数 |
@ApiProperty | 用对象接收参数时,描述对象的一个字段 |
参考文章:
1、 SpringBoot集成swagger-ui以及swagger分组显示
2、IDEA报错之Failed to start bean ‘documentationPluginsBootstrapper‘问题及解决方案
3、swagger3.0访问后台地址
4、集成Springfox 3.0.0