Prevent codes from reporting error when pom.xml is not reinstalled.

This commit is contained in:
jjnnzb 2020-12-27 21:53:36 +08:00
parent 4f3b6057b6
commit d4af8138d0

View File

@ -1,5 +1,6 @@
package com.github.kfcfans.powerjob.server.common.config; package com.github.kfcfans.powerjob.server.common.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -9,12 +10,10 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import javax.annotation.Resource;
import static springfox.documentation.builders.PathSelectors.any; import static springfox.documentation.builders.PathSelectors.any;
/** /**
* Swagger UI 配置 * Configuration class for Swagger UI.
* *
* @author tjq * @author tjq
* @author Jiang Jining * @author Jiang Jining
@ -24,18 +23,25 @@ import static springfox.documentation.builders.PathSelectors.any;
@EnableSwagger2 @EnableSwagger2
public class SwaggerConfig { public class SwaggerConfig {
@Resource private final BuildProperties buildProperties;
private BuildProperties buildProperties;
public SwaggerConfig(@Autowired(required = false) final BuildProperties buildProperties) {
this.buildProperties = buildProperties;
}
@Bean @Bean
public Docket createRestApi() { public Docket createRestApi() {
String version = "3.3.3";
if (buildProperties != null) {
version = buildProperties.getVersion();
}
// apiInfo()用来创建该Api的基本信息这些基本信息会展现在文档页面中 // apiInfo()用来创建该Api的基本信息这些基本信息会展现在文档页面中
ApiInfo apiInfo = new ApiInfoBuilder() ApiInfo apiInfo = new ApiInfoBuilder()
.title("PowerJob") .title("PowerJob")
.description("Distributed scheduling and computing framework.") .description("Distributed scheduling and computing framework.")
.license("Apache Licence 2") .license("Apache Licence 2")
.termsOfServiceUrl("https://github.com/KFCFans/PowerJob") .termsOfServiceUrl("https://github.com/KFCFans/PowerJob")
.version(buildProperties.getVersion()) .version(version)
.build(); .build();
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)