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,变量值 ...
随机推荐
- Eureka与Zookeeper的区别
ACID与ACP的介绍
- Git的使用--如何安装和使用 github,让小白不在那么白 (一)(超详解)
简介 刚开始写了关于如何将本地代码上传到github上,但是有些小伙伴们不清楚如何安装Git,这一篇就给小伙伴们普及一下Git的安装和使用.适合刚开始用git的小白,大神或者大佬请绕道. 实际项目开发 ...
- UWP 使用Launcher 启动迅雷
不得不说UWP有些地方真的不方便! 另外也要夸一下迅雷,还是蛮不错的! 代码 await Launcher.LaunchUriAsync(new Uri("magnet:?xt") ...
- PyCharm创建Django项目并连接mysql数据库
0. 安装Django pip install django 1. 新建项目 注:我的Pycharm为社区版,创建项目时,File->New Project- 显示为: 注意勾选内容. 如果 ...
- 【JVM】【linux】linux上执行jmap命令查看JVM内存使用情况,报错:sun.jvm.hotspot.debugger.NoSuchSymbolException: Could not find symbol "gHotSpotVMTypes" in any of the known library name
运行命令: jmap -heap 报错如下: Attaching to process ID , please wait... sun.jvm.hotspot.debugger.NoSuchSymbo ...
- navicat for mongodb12破解
网上搜了一圈,都不管用.大多都有病毒,最后还是通过搜索github解决问题. 破解文件:https://github.com/DoubleLabyrinth/navicat-keygen/releas ...
- 【转】Redis的各项功能解决了哪些问题?
作者:Blackheart 出处:http://linianhui.cnblogs.com 先看一下Redis是一个什么东西.官方简介解释到:Redis是一个基于BSD开源的项目,是一个把结构化的数据 ...
- net core 记录自定义端口多个方式
1.直接修改 . 2.代码定义 public class Program { public static void Main(string[] args) { CreateWebHostBuilder ...
- fancybit个人简介
程序员一枚 熟悉C C++ C# js lua等多种常见开发语言 熟悉Unity游戏开发 node.js pomelo和C# scut 网游后端框架 做过.net和php网站后端 二次元文化爱好者 有 ...
- delegate里的Invoke和BeginInvoke
Invoke和BeginInvoke都是调用委托实体的方法,前者是同步调用,即它运行在主线程上,当Invode处理时间长时,会出现阻塞的情况,而BeginInvod是异步操作,它会从新开启一个线程,所 ...