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在线文档 前言 不得不说, ...
随机推荐
- DB2知识文档
DB2知识文档 一.db2 基础 基本语法 注释:“--”(两个减号) 字符串连接:“||” 如set msg=’aaaa’||’bbbb’,则msg为’aaaabbbb’ 字符串的引用:‘’(一定用 ...
- C# winform 自定义鼠标光标
第一种:(调用系统API)首先引入两个命名空间代码如下: using System.Runtime.InteropServices;using System.Reflection;导入API代码如下: ...
- emacs 考场配置
先存在这里,免得等回来乱搞的时候把自己的配置搞丢了qwq (custom-set-variables '(custom-enabled-themes (quote (tango-dark)))) (c ...
- coderfoces D. Gourmet choice
D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes 题目链接: https: ...
- VSM Import Cluster功能验证一(准备篇)
一.概述 本文档记录了VSM Import Cluster功能验证过程及过程中遇到的问题. 二.准备 2.1.网络规划 1) Management Network:VSM控制节点对其他节点的管理网络, ...
- jquery.nav.js定位导航滚动插件
jQuery.nav.js插件代码: /* * jQuery One Page Nav Plugin * http://github.com/davist11/jQuery-One-Page-Nav ...
- kali linux之Bdfproxy
Bdfproxy(mitmproxy) 基于流量劫持动态注入shellcode(arp欺骗,dns欺骗,流氓ap) 步骤: 开启流量转发---------sysctl -w net.ipv4.ip_f ...
- EXPORT Man Information for Linux use COMMAND col
col命令 是一个标准输入文本过滤器,它从标注输入设备读取文本内容,并把内容显示到标注输出设备.在许多UNIX说明文件里,都有RLF控制字符.当我们运用shell特殊字符>和>>,把 ...
- dbproxy-main函数
main主函数 /home/id/lua.lua/home/id/lua-c/lua.lua/home/id/lua-c/metatable.lua/home/id/lua-c/1.lua int m ...
- 主流服务器虚拟化技术简单使用——Xen(二)
管理多台Xen主机可以使用GUI工具virt-manager和xm.xl等命令行工具. Tips:hypervisor一定要选到Xen web管理工具 Xen也有一个简易web管理工具叫xenwebm ...