引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
添加配置文件
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.pathMapping("/")
.select()
/**
* 需要配置扫描的controller包
*/
.apis(RequestHandlerSelectors.basePackage("com.content.dictation.apicontroller"))
.paths(PathSelectors.any())
.build().apiInfo(new ApiInfoBuilder()
.title("关于文字图像识别API说明")
.contact(new Contact("Jenson","https://blog.youkuaiyun.com/coderping",""))
.build());
}
}
注解说明,可以查阅官方文档或其他博客
controller类的配置
最后大功告成