swagger3.0.0访问页面404解决

查询百度发现3.0.0
版本更换了访问路径为:/swagger-ui/index.html
重新访问后依然404。
访问官方https://github.com/springfox/springfox-demos发现依赖更换了:
原先的依赖
1 2 3 4 5 6 7 8 9 10 11
| <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.8.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency>
|
现在的依赖
1 2 3 4 5
| <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
|
同时移除了注解@EnableSwagger2

嵌套依赖:

使用
可以不使用@EnableSwagger2注解,配置类与之前一样,启用springboot应用后访问:/swagger-ui/index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| @Configuration
public class Swagger2Config{ @Bean public Docket createRestApi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("cn.yuencode.admin.controller"))
.paths(PathSelectors.any()) .build(); }
private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("SwaggerUI") .description("oisp") .contact(new Contact("jiaxiaoyu","https://www.yuencode.cn","jarryxy@qq.com")) .version("1.0") .build(); } }
|
成功访问:
