springmvc 配置swagger
环境:spring 4.1.6
jdk:1.8.0_66
1.首先导入swagger依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
注意,有些blog上说要下载swagger的html页面,至少我用的这个版本不用,因为 springfox-swagger-ui.jar
中已经包含了。
2.在spring配置文件中声明静态资源和swaggerBean初始化
<bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/>
<mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/>
<mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
3.在浏览器中访问页面:
http://127.0.0.1:8080/swagger-ui.html