为了方便调试,先搞个swagger进来再说.不然想调试好麻烦
引入pom:
<!-- swagger基础依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>
<!-- doc-ui依赖-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
启动类添加@EnableOpenApi注解就可以了.
问题来了,我看网上各种博客这样那样的,归根结底最简单swagger3集成方式就是这样.但是,写好的接口看不到,在swagger页面上怎么都看不到.
@Configuration
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
//重点在于这行代码.没有这个怎么都不行
return new Docket(DocumentationType.OAS_30);
}
}
新增一个配置类.搞定.类型可以根据自己的需要设置不通的,但是必须要设置.这个config还可以配置很多的东西,可以根据自己的需求去配置.这里只是写一个最简单的集成可用
还要注意一点是,swagger3的请求地址变了127.0.0.1:端口/context-path/swagger-ui/
这个ui的请求地址是127.0.0.1:端口/context-path/doc.html
context-path是项目配置的前缀