You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

66 lines
2.3 KiB

package {{ package.Common }}.config;
//--- 固定引入 ---//
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
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;
//--- 固定引入 ---//
/**
* Swagger2配置类
* 在与spring boot集成时,放在与Application.java同级的目录下。
* 通过@Configuration注解,让Spring来加载该类配置。
* 再通过@EnableSwagger2注解来启用Swagger2。
* @Author: {{author}}
* @Date: {{date}}
* @Wechat: {{ wechat }}
* 访问地址:http://localhost:port/api/doc.html
*/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2 {
@Value("${swagger.show}")
private boolean swaggerShow;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.enable(swaggerShow)// 设置正式环境不显示Swagger2
.select()
// 配置多个扫描路径
.apis(
Predicates.or(
RequestHandlerSelectors.basePackage("{{package.Controller}}")
)
)
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
// name:作者,url:通常项目地址,email:邮箱
Contact contact=new Contact("{{author}}","https://blog.csdn.net/Extraordinarylife"," ");
return new ApiInfoBuilder()
.title("数据中心接口文档")//标题
.description("数据中心相关接口文档")// 描述
.contact(contact)
.version("1.0")//版本
.build();
}
}