1、调用Gitlab API获取项目commit ID
2、编辑 Swagger2.java
@Configuration
@EnableSwagger2
@EnableWebMvc
public class Swagger2 extends WebMvcConfigurerAdapter {
#获取配置
@Value("${ctovp.project.versionUrl}")
private String versionUrl;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
}
@Bean
public Docket controllerApi() {
#调用配置接口API
String version = HttpClientUtil.httpGetRequest(versionUrl);
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("标题:项目管理平台")
.description("描述:用于各平台接口调用")
.contact(new Contact("ctovp",null,null))
.version("版本号:"+version)
.build())
.select()
.apis(RequestHandlerSelectors.basePackage("com.ctovp.ws"))
.paths(PathSelectors.any())
.build();
}
}
3、看一下效果