在官方文档3.0以后已经没有这个注解了
@EnableSwagger2
所以要替换下面的依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
直接去看官网: Swagger官网
把上面的依赖替换成下面这个
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
再配置一下SwaggerConfig
@Configuration
public class SwaggerConfig {
//配置了Swagger的Docket的bean实例
//enable是否启动swagger,如果为False则Swagger不能在浏览器访问
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//RequestHandlerSelectors,配置要扫描接口的方式
//basePackage:指定要扫描的包
//any():扫描全部
//none():不扫描
//.withClassAnnotation():扫描类上的注解
//.withMethodAnnotation():扫描方法上的注解
.apis(RequestHandlerSelectors.basePackage("com.xiaotang.controller"))
//paths()过滤什么路径
/*.paths(PathSelectors.ant("/mi/**"))*/
.build();
}
//作者信息
Contact contact = new Contact("小唐","xiaotangstudio.cn","1738743304@qq.com");
//配置Swagger 信息 = ApiInfo
private ApiInfo apiInfo()
{
return new ApiInfo("小唐的Api文档",
"好好看文档",
"1.0",
"xiaotangstudio.cn",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<>());
}
}
导入依赖 重启项目
访问:http://localhost:8080/swagger-ui/index.html
完美解决