Spring Boot use of Maven properties configured in yaml
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Using Maven properties inside application.yml is really a build-time resource-filtering question, not a Spring Boot runtime feature by itself. The key is to separate two kinds of placeholders: values Maven should expand during the build and values Spring should resolve later when the application starts.
Understand Build-Time Versus Runtime Expansion
These two placeholder systems look similar but serve different purposes:
- Maven properties are expanded while the project is built
- Spring placeholders are resolved when the application runs
That distinction matters because careless filtering can accidentally replace Spring expressions that were supposed to stay dynamic.
A Typical Build-Time Version Example
Suppose you want the application version from pom.xml inside YAML:
Those @...@ tokens are intended for Maven resource filtering. After the build, the generated resource file contains the real values.
Using @...@ instead of ${...} is helpful because Spring already uses ${...} for runtime property placeholders. Keeping the delimiters different avoids ambiguous behavior.
Enable Resource Filtering in Maven
In pom.xml, enable filtering for resources:
Once filtering is enabled, Maven replaces tokens such as @project.version@ while copying resources into the build output.
If your project uses Spring placeholders heavily, be deliberate about delimiters so Maven does not try to expand values meant for Spring.
Keep Spring Runtime Placeholders Intact
You can still use normal Spring placeholders in the same YAML file:
Here:
- '
@project.version@is resolved at build time by Maven' - '
${APP_EXTERNAL_URL:...}is resolved at runtime by Spring'
That separation is usually the cleanest approach.
Bind the Result Like Any Other Spring Property
Once the application starts, Spring just sees the filtered YAML as ordinary configuration:
From Spring Boot’s perspective, there is nothing special about these values anymore. Maven already did its part before the app launched.
Consider Build Info for Metadata
If the goal is specifically application metadata such as version, artifact, and group, another option is to generate build information instead of filtering YAML manually. That can be cleaner when you want standardized build metadata rather than general-purpose config interpolation.
Manual filtering is still fine when the build property truly belongs in configuration, but not every version value has to be copied into application.yml.
Common Pitfalls
- Expecting Spring Boot to resolve Maven properties automatically at runtime without Maven resource filtering.
- Using
${project.version}directly and colliding with Spring’s own ${...}placeholder syntax. - Enabling aggressive filtering and accidentally replacing placeholders that Spring was supposed to handle later.
- Putting secrets into Maven-filtered resources when they should come from environment-specific runtime sources instead.
- Forgetting that filtered YAML values become fixed at build time, not deployment time.
Summary
- Maven properties in
application.ymlare handled during the build, not by Spring Boot at runtime. - Use resource filtering and a distinct delimiter such as
@project.version@for build-time expansion. - Keep Spring runtime placeholders such as
${APP_EXTERNAL_URL}separate from Maven tokens. - Treat the filtered YAML as ordinary Spring configuration once the application starts.
- Choose build metadata or filtered YAML based on whether the value is really configuration or just artifact metadata.
- Be explicit about which tool owns each placeholder so configuration stays predictable.
Related reading
- Spring boot validation annotations Valid and NotBlank not working
- Spring Boot Value Properties
- Spring Boot version versus Spring Framework version?
- Spring Boot War deployed to Tomcat
- Spring boot Webclient's retrieve vs exchange
- Spring Boot Websockets in Wildfly
- Spring Boot with Apache Tiles
- Spring Boot with embedded Tomcat behind Apache proxy

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.