swagger 配置- ssm
swagger 配置 - ssm
swagger 是一个用来看接口的工具,具体效果如下,这里用的是swagger2

1、porm.xml
<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>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.9.5</version>
</dependency>
2、swagger 配置

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.PathSelectors;
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
@EnableSwagger2
@EnableWebMvc
public class Swagger2 { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.common.base.modules"))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Swagger").description("show").termsOfServiceUrl("no terms of service")
.version("2.0")
.build();
} }
3、在spring-mvc.xml的配置文件里面配置扫描到上面那个 swagger 2 文件
<context:component-scan base-package="com.common.base.swagger" />
4、controller 配置例 - 配置 Api
@RestController
@RequestMapping("/items")
public class ItemController { @Autowired
private ItemService itemService; @RequestMapping(value="/queryItems", method=RequestMethod.GET)
@ApiOperation(value="Items",notes="Items")
public JSONObject queryItems(HttpServletRequest request) {
return itemService.queryItem((CommonUtil.request2Json(request)));
}
}
5、完成 ip + 端口: swagger-ui.html

(注:如果 shiro 拦截的话在shiro的xml配置文件的 filterChain 里面加入以下,但是接口还是会被拦截, 怎么解啊
或者 注释掉 web.xml 的shiro 拦截)

<!-- swagger设置匿名访问 -->
/swagger-ui.html/** = anon
/swagger-resources/** = anon
/v2/api-docs = anon
swagger 配置- ssm的更多相关文章
- 一、Swagger配置
一.Swagger配置 1.注解不显示 SwaggerConfig文件下 //c.IncludeXmlComments(GetXmlCommentsPath()): 内下面添加: c.Inclu ...
- 配置ssm 时, web.xml 文件无 # 自动代码提示
环境:STS 版本:spring-tool-suite-3.8.1.RELEASE-e4.6-win32-x86_64 配置ssm 时, web.xml 文件无 如下图蓝色圈范围内的提示 问题与 链接 ...
- Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)
Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...
- swagger配置
1.pom.xml <!--swagger2--> <dependency> <groupId>io.springfox</groupId> <a ...
- 尝试从零开始构建我的商城 (二) :使用JWT保护我们的信息安全,完善Swagger配置
前言 GitHub地址 https://github.com/yingpanwang/MyShop/tree/dev_jwt 此文对应分支 dev_jwt 此文目的 上一篇文章中,我们使用Abp vN ...
- webapi Swagger 配置 services.BuildServiceProvider() 报警 ASP0000 问题处理
问题起源 网上的常见配置 Swagger 配置 在Startup类的 ConfigureServices 使用 services.BuildServiceProvider() ,其中有段代码如下: v ...
- 《Asp.Net Core3 + Vue3入坑教程》-Net Core项目搭建与Swagger配置步骤
简介 <Asp.Net Core3 + Vue3入坑教程> 此教程仅适合新手入门或者前后端分离尝试者.可以根据图文一步一步进操作编码也可以选择直接查看源码.每一篇文章都有对应的源码 教程后 ...
- SpringBoot初探之Swagger配置
Swagger是一个用于描述和测试restful接口的工具,只要在定义restful接口时增加一些类和方法的描述注解,通过很简单的配置就可以得到一个展示接口定义页面,也可以在页面上设置参数提交测试接口 ...
- java web,从零开始,一步一步配置ssm(Spring+SpringMVC+MyBatis)框架
1.安装JDK: 安装之后要配置环境变量,在系统变量里: 新建变量名JAVA_HOME,变量值C:\Program Files\Java\jdk1.8.0_77: 新建变量名CLASSPATH,变量值 ...
随机推荐
- TypeError: Dense_net() takes 0 positional arguments but 1 was given
书写孪生网络的时候出现的错误,调用单通道时出现如下错误. 看了别人写的博客大概和类内的初始化还有self之类的有关系,没有弄清楚.将单通道的文件在函数外声明,在函数内统一调用可以解决这个问题
- c# 自动给版本升级,遇9变0且前面一个版本加1
/// <summary> /// 版本辅助类 /// 创建人: /// 创建时间:2019-11-18 13:53:55 /// </summary> public clas ...
- 基于JRebel开发的MybatisPlus热加载插件
前言 前天项目中使用了mybatis-plus,但是搭配Jrebel开发项目时,发现修改mapper的xml,或者mapper方法中的注解,Jrebel并没有能够reload mapper.于是就有了 ...
- sql server生成随机id
SQL Server中生成随机ID的函数是newId(),但是这样生成出来的随机ID是36位带[-]符号的. select newId(); -- 746516E0-95D6-4BAF-8826-6C ...
- VB.net 通过句柄操作其他窗口
Imports System.TextImports System.Runtime.InteropServices Public Class Form1 ' 相关API函数声明,注释掉的这里没用 ...
- 在IE中点击转跳,并打开chorme浏览器继续浏览指定页面,IE自定义ocx控件开发
因项目需要,需要开发一个功能:在IE中点击转跳,并打开chorme浏览器继续浏览指定页面. 分析需求后,参考了: https://www.cnblogs.com/ffjiang/p/7908025.h ...
- np.broadcast_to()的函数使用及维度增加的表达
import numpy as npanchors=np.ones((2,3))anchor = np.broadcast_to(anchors, (5,)+anchors.shape) # 标红字体 ...
- 线程---Day22
并发与并行 并发:指两个或多个事件在同一个时间段内发生. 并行:指两个或多个事件在同一时刻发生(同时发生) 在操作系统中,安装了多个程序,并发指的是在一段时间内宏观上有多个程序同时运行,这在单CPU系 ...
- 为什么你要使用这么强大的分布式消息中间件——kafka
为什么是kafka? 在我们大量使用分布式数据库.分布式计算集群的时候,是否会遇到这样的一些问题: 我们想分析下用户行为(pageviews),以便我们设计出更好的广告位 我想对用户的搜索关键词进行统 ...
- k8s时区问题解决方案
前几天在使用k8s中的CronJob时发现了一个很奇怪的问题, 按照官方文档的demo跑起来是没有任何问题的, 但是当我想要设置每天一个固定时间点例如12点20执行一个job的时候,到了时间之后无论如 ...