`
lfwer
  • 浏览: 84200 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

swagger2与springmvc的整合

阅读更多

1 添加如下依赖:

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
</dependency>

 

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", "lfwer@163.com");
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静态资源文件路径配置

<mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/>
<mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics