swagger3 配置
在pom.xml添加swagger3.0的依赖:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
创建SwaggerConfig 配置类
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@EnableOpenApi //使用Swagger3.0的Api文档
@Configuration
@EnableWebMvc //使能Swagger
public class SwaggerConfig{
@Bean
public Docket docketCategory() {
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
// 分组名称
.groupName("default")
//使能swagger
.enable(true)
.select()
//设置接口包名
.apis(RequestHandlerSelectors.basePackage("com.example.controler"))
//设置请求路径开头的接口
.paths(PathSelectors.ant("/**"))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("接口总览")
.description("测试")
.version("1.0")
.build();
}
}
访问:http://localhost:8080/swagger-ui/index.html
浙公网安备 33010602011771号