1、pom.xml引入swagger插件
io.springfox springfox-swagger2 2.5.0 io.springfox springfox-swagger-ui 2.5.0 com.github.caspar-chen swagger-ui-layer 0.0.4 com.drore.cloud swagger-bootstrap-ui 1.4
2、配置spring-mvc.xml注入swagger扫描配置
3、创建MySwaggerConfig.java 配置中心实例
package com.**.common.filter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; 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; @EnableWebMvc @EnableSwagger2 @ComponentScan(basePackages = {"com.**"}) @Configuration public class MySwaggerConfig extends WebMvcConfigurerAdapter { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.**")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("**系统数据接口文档") .termsOfServiceUrl("https://test-**.com") .contact("**@**.com") .version("0.0.1") .description("**系统数据接口文档") .build(); } } 注:若工程使用的spring Shiro等安全拦截 需进行静态资源过滤,
/v2/** = anon /doc.html = resource /menu.json = resource /docs.html = resource /webjars/** = anon /swagger-resources/** = anon /swagger-ui.html = resource