如何增加个 swagger

-- POM.xml

<!-- swagger-mvc -->       <dependency>
           <groupId>io.springfox</groupId>
           <artifactId>springfox-swagger2</artifactId>
           <version>2.4.0</version>
       </dependency>
       <dependency>
           <groupId>io.springfox</groupId>
           <artifactId>springfox-swagger-ui</artifactId>
           <version>2.4.0</version>
       </dependency>
       <dependency>
           <groupId>com.google.guava</groupId>
           <artifactId>guava</artifactId>
           <version>15.0</version>
       </dependency>
       <dependency>
           <groupId>com.fasterxml</groupId>
           <artifactId>classmate</artifactId>
           <version>1.1.0</version>
       </dependency>

-- spring-mvc-config.xml


<!-- swagger -->
<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/**" />

<mvc:resources mapping="/docs/**" location="/WEB-INF/docs/" />

增加controller

package com.hf.kafka.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import springfox.documentation.annotations.ApiIgnore;

/**
 * Home redirection to swagger api documentation
 */
@ApiIgnore
@Controller
public class ApiController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home() {
        return "redirect:swagger-ui.html";
    }

    @RequestMapping(value = "/docapi", method = RequestMethod.GET)
    public String docApi() {
        return "redirect:swagger-ui.html";
    }
}

在对应的接口的controller上加上swagger

@Controller
@Api(tags = "Kafka数据解析", value = "/kafka") \\增加的swagger调用
@RequestMapping("/kafka")
public class KafkaController extends BaseController {
##############################################################下面是原来的controller
@RequestMapping(value = "/exec/{type}", method = RequestMethod.GET)
    @ResponseBody
    public synchronized String executeParse(@PathVariable("type") String type){
########################################################################下面是增加的swagger后的
    @ApiOperation(value = "/exec/{type}", httpMethod = "/exec/{type}", response = String.class, notes = "Kafka数")
    @RequestMapping(value = "/exec/{type}", method = RequestMethod.GET)
    @ResponseBody
    public synchronized String executeParse(@ApiParam(value = "二手房:szhome<br>", required = true) @PathVariable("type") String type){



↙↙↙阅读原文可查看相关链接,并与作者交流