In Spring projects we often use maven variables to switch environments — for example the @activatedProperties@ placeholder, passed in at maven packaging time so the config file can switch between runtime environments.
Today’s problem: in SpringCloud, a bootstrap.yml file used the @activatedProperties@ placeholder, but no matter how I rebuilt the package, it was never substituted — it ended up verbatim in the packaged artifact, and the application wouldn’t run.
Use Maven Filtering
Maven filtering is a feature of the Maven build process that dynamically replaces properties in files during the build.
For example, you can define a property in the project’s config and reference it in a file; during the build, Maven replaces the property with its actual value.
So we need to modify the build section of pom.xml and add filtering configuration:
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Now Maven will replace properties in the file with their actual values during the build.
For more questions, the official docs are the best reference: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
