测试发现,项目大了,项目启动会卡,接口访问也会卡,最好改为外部api接口维护 https://rap.chinamcloud.com/org/index.do


    io.springfox
    springfox-swagger2
    2.6.1



    io.springfox
    springfox-swagger-ui
    2.6.1



    com.fasterxml.jackson.core
    jackson-core
    2.7.8


    com.fasterxml.jackson.core
    jackson-databind
    2.7.8


    com.fasterxml.jackson.core
    jackson-annotations
    2.7.8

    增加配置类:
    //@Configuration和@WebAppConfiguration都可以使用,有的博客写果你的项目引入junit测试,此处需要使用@WebAppConfiguration,如果没有使用junit使用@Configuration
    //@WebAppConfiguration
    //这个ComponentScan我配置的时候没有用处,通过限定要生成文档的controller是通过apis()和paths()控制的
    //@ComponentScan(basePackages = “com.fh.controller.api.goods”)//扫描control
    @EnableWebMvc
    @Configuration
    @EnableSwagger2
    @ComponentScan(“com.toyor.msims.controller.auditmag.“)
    public class SwaggerConfig {
    @Bean
    public Docket api() {
    System.out.println(“——XIN——2018/7/11 下午12:58 Line:22,当前类=SwaggerConfig.api()”);
    return new Docket(DocumentationType.SWAGGER_2)
    .select()
    /**

    重要的两个方法:
    apis():指定要生成文档的接口包基本路径
    paths():指定针对哪些请求生成接口文档
    参考官方资料:http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
    **/
    //.apis(RequestHandlerSelectors.any())
    .apis(RequestHandlerSelectors.basePackage(“com.toyor.msims.controller.auditmag”))
    //.paths(PathSelectors.any())
    .paths(PathSelectors.ant(“/AuditSet/
    “))
    //.paths(PathSelectors.ant(“/mobile/“))
    /.paths(Predicates.or(
    PathSelectors.regex(“/mobile/.
    “)
    //PathSelectors.regex(“.cw/user.“),)
    ))
    /
    .build()
    .apiInfo(apiInfo());
    }
    private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
    .title(“aaaa项目接口文档”)
    .description(“aaaa API接口文档”)
    .version(“1.0.0”)
    .termsOfServiceUrl(“”)
    .license(“”)
    .licenseUrl(“”)
    .build();
    }
    }
    spring-mvc.xml配置:


    <mvc:resources mapping=”/webjars/
    “ location=”classpath:/META-INF/resources/webjars/“ />


    web.xml配置:

    springMVC
    *.do

    /v2/api-docs
    /swagger-resources
    /swagger-resources/configuration/security
    /swagger-resources/configuration/ui

    测试控制器:
    @Api(tags=”测试接口” )
    @RestController
    @RequestMapping(“/mobile/ocr/“)
    public class OcrController {
    @ApiOperation(value = “查询ocrUrl”, notes = “”, httpMethod = “POST”,response = Void.class)
    @ApiImplicitParams ({
    @ApiImplicitParam(name = “vin:底盘号”, value = “”),
    @ApiImplicitParam(name = “vin:发动机”, value = “1”),
    @ApiImplicitParam(name = “vin:aaa”, value = “2”),
    @ApiImplicitParam(name = “vin:bbb”, value = “”),
    })
    @RequestMapping(value = “/getIdCardOcrUrl”)
    public void getIdCardOcrUrl(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException {
    String aaa = “xxx”;
    }
    }