
一般都是在已经很完善的项目里面,去集成这个 swagger ,我这就反其道而行之,仔细看看这个 swagger 到底都依赖些什么jar包。
让你好好了解下这个东西,出了些问题的话,也可以简单的处理下。
我这就是以一个非常简单的 maven hello world 项目的基础上,去集成这个 swagger 的实践记录。
所以,你这得有个如上的简单项目。
我这有以前的链接,可以供小白们参考。
先是创建个简单的hello world 的 maven web项目,参见下面的链接。
IntelliJ IDEA 创建 hello world Java web Maven项目从头到尾都有图有真相2017版本
然后就是在上面的简单项目里面加上spring mvc 相关的东西。参见下面的链接。
Java springmvc web项目,基于maven的hello world入门级项目使用IntelliJ IDEA 2017版本
上面的2个链接都仔细实践过之后,准备工作就OK啦。
开始,怎么集成这个swagger
先是pom.xml的 dependency 依赖的添加。
为了一览全貌,我就把全部的依赖放这了,因为是个超简单的项目,所以这个依赖很少,方便观众,看清楚,每个依赖都是干啥的。
<dependencies>
<!-- Spring MVC support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!--JSTL-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<!-- swagger2 核心依赖 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<!-- swagger-ui 为项目提供api展示及测试的界面 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<!-- 集成 swagger 的时候,缺少这个 jar包是不OK的-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-58246-1.html