http://localhost:8001/swagger-ui.html 访问地址
导入相应坐标
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
开启jopo注解配置(使用代码生成器)
写一个单独的commons模块
service_swagger子模块
对应开发代码的包写一个SwaggerConfig的类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webApiInfo())
.select()
// .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("网站-课程中心API文档")
.description("本文档描述了课程中心微服务接口定义")
.version("1.0")
.contact(new Contact("Helen", "http://atguigu.com", "55317332@qq.com"))
.build();
}
}
在项目程序入口加上
@ComponentScan(basePackages="com.atguigu") 注解
@Api(description="讲师管理模块")
@ApiOperation("所有讲师列表")
@ApiParam(name="id", value="讲师ID",required = true)