SwaggerConfig.java 1.75 KB
package com.diligrp.swaggerConfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * com.wlqq.pk.server.swagger
 * 16/1/13
 *
 * @author weiming.liao
 */

@Configuration
@EnableWebMvc
@EnableSwagger2
//@ComponentScan(basePackages = {"com.b2c.myapp.api"})
public class SwaggerConfig extends WebMvcConfigurerAdapter {

    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.diligrp.mobsite.getway.web.api";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

    }

    @Bean
    public Docket swaggerSpringMvcPlugin(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.select().apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE)).build();
        ApiInfo apiInfo = new ApiInfo("咱的APP", "移动网关接口", "1.1", "urn:tos", "b2c", "account-park", "http://zandeapp.com");
        docket.apiInfo(apiInfo);
        return docket;
    }

}