From 90399a560d9cdcdf58123ead422b1b9dcb28f2f9 Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Sun, 1 Mar 2015 20:42:05 +0800 Subject: [PATCH] Update and rename 40.4.1. Automatically expand info properties at build time to 40.4.1. Automatically expand info properties at build time.md --- ...cally expand info properties at build time | 0 ...ly expand info properties at build time.md | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+) delete mode 100644 V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time create mode 100644 V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time.md diff --git a/V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time b/V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time deleted file mode 100644 index e69de29..0000000 diff --git a/V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time.md b/V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time.md new file mode 100644 index 0000000..e7019f7 --- /dev/null +++ b/V. Spring Boot Actuator: Production-ready features/40.4.1. Automatically expand info properties at build time.md @@ -0,0 +1,55 @@ +### 40.4.1. 在构建时期自动扩展info属性 + +你可以使用已经存在的构建配置自动扩展info属性,而不是对在项目构建配置中存在的属性进行硬编码。这在Maven和Gradle都是可能的。 + +**使用Maven自动扩展属性** + +对于Maven项目,你可以使用资源过滤来自动扩展info属性。如果使用spring-boot-starter-parent,你可以通过`@..@`占位符引用Maven的'project properties'。 +```java +project.artifactId=myproject +project.name=Demo +project.version=X.X.X.X +project.description=Demo project for info endpoint +info.build.artifact=@project.artifactId@ +info.build.name=@project.name@ +info.build.description=@project.description@ +info.build.version=@project.version@ +``` +**注**:在上面的示例中,我们使用project.*来设置一些值以防止由于某些原因Maven的资源过滤没有开启。Maven目标`spring-boot:run`直接将`src/main/resources`添加到classpath下(出于热加载的目的)。这就绕过了资源过滤和自动扩展属性的特性。你可以使用`exec:java`替换该目标或自定义插件的配置,具体参考[plugin usage page](http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/maven-plugin/usage.html)。 + +如果你不使用starter parent,在你的pom.xml你需要添加(处于元素内): +```xml + + + src/main/resources + true + + +``` +和(处于内): +```xml + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + @ + + + +``` +**使用Gradle自动扩展属性** + +通过配置Java插件的processResources任务,你也可以自动使用来自Gradle项目的属性扩展info属性。 +```java +processResources { + expand(project.properties) +} +``` +然后你可以通过占位符引用Gradle项目的属性: +```java +info.build.name=${name} +info.build.description=${description} +info.build.version=${version} +```