注释掉2.0引入的俩包
直接引入3.0
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
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;
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//TODO 改为你项目使用的controller包目录
.apis(RequestHandlerSelectors.basePackage("com.example.controller"))
.paths(PathSelectors.any())
.build();
}
//构建api的详细信息方法
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("xx接口文档")
//版本号
.version("1.0")
//描述
.description("swagger3.0的为基础的文档哟")
.build();
}
}
最后配置文件改变mvc匹配规则即可
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
最后
swagger2.0访问地址是:
http://localhost:8080/swagger-ui.html
swagger3.0地址是:
http://localhost:8080/swagger-ui/index.html