Maven配置
在pom.xml中加入依赖
io.springfox
springfox-swagger2
2.7.0
io.springfox
springfox-swagger-ui
2.7.0
与SpringMvc集成
增加JavaConfig配置文件
@Configuration
@EnableWebMvc
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket buildDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildApiInf())
.host("localhost:8080")
.select()
.apis(RequestHandlerSelectors.basePackage("com.dianping.orderdish.webapi"))//controller路径
.paths(PathSelectors.any()).build();
}
private ApiInfo buildApiInf() {
return new ApiInfoBuilder()
.title("RestAPI Docs")
.termsOfServiceUrl("http://www.github.com/kongchen/swagger-maven-plugin")
.build();