swagger屏蔽某些接口

swagger会扫描package下面的所有接口,如果我有一些接口不想在页面中显示,应该如何做?

@ApiIgnore

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @since: @ApiIgnore swagger屏蔽某些接口
 */
@ApiIgnore
@Controller
public class MyErrorController implements ErrorController {

    private final static Logger logger = LogManager.getLogger(MyErrorController.class);

    @RequestMapping(value = "/error", method = RequestMethod.GET)
    public String handleError(HttpServletRequest request) {
        //获取statusCode:401,404,500
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        logger.error("获取StatusCode  :" + statusCode);
        if (statusCode == 401) {
            return "/401";
        } else if (statusCode == 404) {
            return "/404";
        } else if (statusCode == 403) {
            return "/403";
        } else {
            return "/500";
        }
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}

参考>>https://github.com/swagger-api/swagger-core/issues/1173

你可能感兴趣的:(java,spring,boot,spring,cloud)