spring+sewwager在线文档生成器使用过程中遇到问题的分享

来源:互联网 发布:红五星3d图库永久域名 编辑:程序博客网 时间:2024/05/22 06:29
刚开始使用springmvc+sewagger时总是弄不好因为网上推荐的是,
<!-- swagger-springmvc -->    <dependency>        <groupId>com.mangofactory</groupId>        <artifactId>swagger-springmvc</artifactId>        <version>1.0.2</version>    </dependency>    <dependency>        <groupId>com.mangofactory</groupId>        <artifactId>swagger-models</artifactId>        <version>1.0.2</version>    </dependency>    <dependency>        <groupId>com.wordnik</groupId>        <artifactId>swagger-annotations</artifactId>        <version>1.3.11</version>    </dependency>    <!-- swagger-springmvc dependencies -->    <dependency>        <groupId>com.google.guava</groupId>        <artifactId>guava</artifactId>        <version>15.0</version>    </dependency>    <dependency>        <groupId>com.fasterxml.jackson.core</groupId>        <artifactId>jackson-annotations</artifactId>        <version>2.4.4</version>    </dependency>    <dependency>        <groupId>com.fasterxml.jackson.core</groupId>        <artifactId>jackson-databind</artifactId>        <version>2.4.4</version>    </dependency>    <dependency>        <groupId>com.fasterxml.jackson.core</groupId>        <artifactId>jackson-core</artifactId>        <version>2.4.4</version>    </dependency>    <dependency>        <groupId>com.fasterxml</groupId>        <artifactId>classmate</artifactId>        <version>1.1.0</version>    </dependency>
使用的是这些jar包,而我下载的swagger是2.0版本以后的。所以总是不成功。于是我看了一下返回页面的json发现json里面的swagger版本都是1.X的版本,这里说一下1.X的版本返回的json中接口信息都是再apis这个字段里面,而2.X后是在paths下面。所以只有两种解决办法,一是让返回的json变成swagger2.X需要的样子,而是降低swaager的版本,可是如果降低swagger版本的话,低版本的可能功能不是很强悍。所以我才用了第一种方法。原来使用swagger2.X时使用的jar包完全不一样。具体据jar包如下:
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --><dependency>    <groupId>io.springfox</groupId>    <artifactId>springfox-swagger2</artifactId>    <version>2.7.0</version></dependency><!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --><dependency>    <groupId>io.springfox</groupId>    <artifactId>springfox-swagger-ui</artifactId>    <version>2.7.0</version></dependency>
然后只需要把下载的swagger包放到你项目能访问到的路径下就可以,然后访问其dist目录下的index.html文件即可,默认是swagger的示例页面,这里你可以在index.html中改成你要显示的页面,即将路径写成,index页面在项目中的路径。
原创粉丝点击