springmvc4集成swagger2
首先在原有的springmvc工程的pom文件中增加swagger
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
增加swagger的配置类
package com.founder.fwpt.config; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableWebMvc
@EnableSwagger2
public class SpringfoxConfig { @Bean
public Docket petApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.founder.fwpt.controller")).build(); } private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("服务平台 API").description("").termsOfServiceUrl("http://localhost:8080").version("1.0").build();
}
}
其中有个信息
basePackage
指定controller的包。
在spring-mvc的拦截其中增加静态资源访问控制。
<mvc:resources
mapping="/webjars/**"
location="classpath:/META-INF/resources/webjars/" />
启动项目,在浏览器中访问
http://localhost:8080/swagger-ui.html
即可。
具体的controller中的@Api注解信息,参考
https://github.com/wkennedy/swagger4spring-web
springmvc4集成swagger2的更多相关文章
- Spring Boot 集成 Swagger2 与配置 OAuth2.0 授权
Spring Boot 集成 Swagger2 很简单,由于接口采用了OAuth2.0 & JWT 协议做了安全验证,使用过程中也遇到了很多小的问题,多次尝试下述配置可以正常使用. Maven ...
- SpringMVC4集成ehcache
前言 使用SpringMVC4集成ehcache来缓存服务器数据. 开发环境 SpringMVC4.ehcache2.6. 项目结构 SpringMVC 集成ehcache 1.pom.xml //除 ...
- SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)
1.pom.xml增加依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...
- springboot集成swagger2构建RESTful API文档
在开发过程中,有时候我们需要不停的测试接口,自测,或者交由测试测试接口,我们需要构建一个文档,都是单独写,太麻烦了,现在使用springboot集成swagger2来构建RESTful API文档,可 ...
- Spring Boot 集成Swagger2生成RESTful API文档
Swagger2可以在写代码的同时生成对应的RESTful API文档,方便开发人员参考,另外Swagger2也提供了强大的页面测试功能来调试每个RESTful API. 使用Spring Boot可 ...
- 集成swagger2构建Restful API
集成swagger2构建Restful API 在pom.xml中进行版本管理 <swagger.version>2.8.0</swagger.version> 给taosir ...
- springboot 集成swagger2
使用Swagger 可以动态生成Api接口文档,在项目开发过程中可以帮助前端开发同事减少和后端同事的沟通成本,而是直接参照生成的API接口文档进行开发,提高了开发效率.这里以springboot(版本 ...
- Spring Boot 入门(七):集成 swagger2
本片文章是基于前一篇写的,<Spring Boot 入门(六):集成 treetable 和 zTree 实现树形图>,本篇主要介绍了spring boot集成swagger2.关于swa ...
- SpringBoot集成Swagger2在线文档
目录 SpringBoot集成Swagger2在线文档 前言 集成SpringBoot 登录接口文档示例 代码 效果 注解说明 总结 SpringBoot集成Swagger2在线文档 前言 不得不说, ...
随机推荐
- python3.7.0安装
如何安装Python的操作步骤: 1.第一步先去python的官方网站下载python的安装包 地址:https://www.python.org/downloads/ 根据自己的系统选择对应的安装包 ...
- python基本算法
算法优劣评判标准 时间复杂度: 定义:用来评估算法运行效率的一个式子 print('Hello World') O(1) for i in range(n): print('Hello World') ...
- ios 相机 自定义 相片的截取
前段时间公司需要做一个身份识别的功能,而系统相机无法满足要求,so自己自定义了. 上代码: .h文件 #import <UIKit/UIKit.h> #import <AVFound ...
- 【FAQ】Could not extract response: no suitable HttpMessageConverter found for respo
原因: 1:某些必须传入的参数没传 2:返回对象的接收类型不一致
- css ie浏览器兼容问题
第一,IE6,不支持小于12px的盒子,任何小于12px的盒子,在IE6中看都大 解决办法很简单,就是将盒子的字号,设置小(小于盒子的高),比如0px. 1 height: 4px; 2 _font- ...
- spring ThreadPoolTaskExecutor使用总结
ThreadPoolTaskExecutor提供TaskDecorator可以实现类似ThreadPoolExecutor.afterExecute()类似功能 taskDecorator主要是对Ru ...
- Jenkins Slave Nodes – using the Swarm Plugin
link: http://www.donaldsimpson.co.uk/2013/03/18/jenkins-slave-nodes-using-the-swarm-plugin/ I’ve bee ...
- maven相关的说明以及通过它来创建项目
1.什么是maven maven的本质是一个项目构建工具 2.maven的作用 那么作为一个项目构建工具我们又为什么要使用它以及好处呢 首先项目构建的本质是什么:项目代码从源代码到程序文件的过程是代码 ...
- 使用chart.js時取消懸浮在圖表頂部的'undefined'標識
解決方法:在options中設置legend項中display屬性為false options: { scales: { yAxes: [{ ticks: { beginAtZero: true } ...
- Three.js 前言
-----------------------------------本文非技术文章,着急开发的小伙伴请绕道----------------------------------------- 最近公司 ...