swagger2与springmvc的整合

阅读更多

1 添加如下依赖:


io.springfox
springfox-swagger2
2.5.0


io.springfox
springfox-swagger-ui
2.5.0

 

2 增加Swagger2Config配置类,只显示使用@Api注解的api。

@Component
@Configuration
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackageClasses = QuartzManagerAction.class)
public class Swagger2Config {
@Bean
public Docket createAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
Contact contact = new Contact("lfw", "http://lfwer.iteye.com", "[email protected]");
ApiInfo apiInfo = new ApiInfoBuilder().license("Apache License Version 2.0").title("定向流量系统").description("Swagger API").contact(contact).version("1.0").build();
return apiInfo;
}
}

  

3 修改springmvc-servlet.xml,增加swagger静态资源文件路径配置


 

你可能感兴趣的:(swagger2与springmvc的整合)