参考资料:https://www.springcloud.cc/spring-boot.html
中文文档2:https://felord.cn/_doc/_springboot/2.1.5.RELEASE/_book/index.html
1. 依赖
很重要
:因为区别于 springMVC 所以依赖的名字和版本要和 springMVC 区别开来
1 2 3 4 5 6 7 8 9 10
| <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.6</version> </dependency>
|
2. 配置类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration @EnableSwagger2
@EnableSwaggerBootstrapUI public class SwaggerConfig {
public static final String PROJECT_NAME = "xx信息登记系统后端"; public static final String PROJECT_VERSION = "1.0.0"; public static final String PROJECT_URL = "www.interview.com";
public static final String SCAN_API_PACKAGE = "com.jerry.interview.controller"; public static final String SCAN_API_PATH = "/**";
public static final String CONTACT_NAME = "Jerry(姜源)"; public static final String CONTACT_URL = PROJECT_URL; public static final String CONTACT_EMAIL = "interview@163.com";
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage(SCAN_API_PACKAGE)) .paths(PathSelectors.ant(SCAN_API_PATH)) .build() .apiInfo(apiInfo()); }
private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(PROJECT_NAME + " 项目接口文档") .description(PROJECT_NAME + " API接口文档") .version(PROJECT_VERSION) .contact(new Contact(CONTACT_NAME, CONTACT_URL, CONTACT_EMAIL)) .termsOfServiceUrl(CONTACT_URL) .license("") .licenseUrl("") .build(); } }
|