- pom.xml
pom.xml文件加入swagger -
<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.3</version></dependency>
编写配置文件
SwaggerConfigurer
-
package com.wly.qc.config;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.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;/*** 注解标示,这是一个配置类,@Configuation注解包含了@Component注解* @aothor wanghc* @date 2022/2/25**/ @EnableSwaggerBootstrapUI//需要登录才加上改配置 @Configuration @EnableSwagger2 public class SwaggerConfigurer {@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.wliyun.qc.controller")).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("后质控系统api文档").description("API").termsOfServiceUrl("").version("1.0").build();} }
application.yml文件内需要添加的内容
-
swagger:production: falsebasic:enable: trueusername: rootpassword: test