Mastering Spring Cloud
上QQ阅读APP看书,第一时间看更新

Application information

The full list of endpoints available for the project is visible in application logs during startup. After disabling security, you can test all of them in your web browser. It's interesting that the /info endpoint does not provide any information by default. If you would like to change this, you might use one of the three available auto-configured InfoContributor beans or write your own. The first of them, EnvironmentInfoContributor, exposes environment keys in the endpoint. The second, GitInfoContributor, detects the git.properties file in the classpath and then displays all necessary information about commits, such as branch name or commit ID. The last one, named BuildInfoContributor, gathers information from the META-INF/build-info.properties file and also displays it in the endpoint. These two properties files for Git and build information can be automatically generated during application build. To achieve this, you should include git-commit-id-plugin in your pom.xml and customize spring-boot-maven-plugin to generate build-info.properties in the way visible in this code fragment:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
<configuration>
<additionalProperties>
<java.target>${maven.compiler.target}</java.target>
<time>${maven.build.timestamp}</time>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<configuration>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>

With the build-info.properties file available, your /info would be a little different than before:

{ 
"build": {
"version":"1.0-SNAPSHOT",
"java": {
"target":"1.8"
},
"artifact":"sample-spring-boot-web",
"name":"sample-spring-boot-web",
"group":"pl.piomin.services",
"time":"2017-10-04T10:23:22Z"
}
}