Giriş
Plugin çalışınca şu dosya yaratılır/build/resources/main/META-INF/build-info.properties
Eğer bu dosya varsa Spring otomatik olarak org.springframework.boot.info.BuildProperties diye bir bean yaratır. Bu bean'in içi şuna benzer
build.artifact=log-version build.group=examples.debuggingspring build.name=log-version build.time=2022-10-09T14\:51\:08.212010400Z build.version=latest
Maven
Açıklaması şöyle
To show the version number associated with the application we must configure it through the pom.xml file, the spring-boot-maven-plugin, and the build-info option. This will automatically create the META-INF/build-info.properties file that will transmit the information to the Spring Boot Admin.
Örnek
Şöyle yaparız
<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>build-info</goal></goals></execution></executions></plugin>
Açıklaması şöyle
We can also add tags to the information of our application that allows us to categorize it, such as the environment where it is deployed. These tags will be transferred through the endpoint info. Configuration example:#using the info endpointinfo.tags.environment=test
Gradle
Şöyle yaparız. Burada BUILD_NUMBER bir Jenkins ortam değişkeniplugins { id 'org.springframework.boot' version '2.6.6' } springBoot { buildInfo() } version = System.getProperty("BUILD_NUMBER", "latest")
Örnek
Bean'i REST olarak dışarıya açmak için şöyle yaparız
@Service public class BuildInfoService { @Autowired BuildProperties buildProperties; @Autowired Environment environment; public BuildInfoResponse getBuildInfo(){ BuildInfoResponse buildInfoResponse = new BuildInfoResponse(); buildInfoResponse.setName(this.buildProperties.getName()); buildInfoResponse.setVersion(this.buildProperties.getVersion()); buildInfoResponse.setTime(this.buildProperties.getTime()); buildInfoResponse.setActiveProfile(this.environment.getActiveProfiles()); buildInfoResponse.setSpringVersion(this.buildProperties.getVersion()); buildInfoResponse.setGroup(this.buildProperties.getGroup()); buildInfoResponse.setArtifact(this.buildProperties.getArtifact()); return buildInfoResponse; } } @RestController @RequestMapping("/${build-info.path}") public class BuildInfoController { @Autowired BuildInfoService buildInfoService; @GetMapping("/build-info") public BuildInfoResponse getBuildInfo() { return this.buildInfoService.getBuildInfo(); } }
Örnek
Burada Spring loglarına versiyon bilgisi eklemekle ilgili bir örnek var.
Hiç yorum yok:
Yorum Gönder