Automatic Property Expansion with Spring Boot

Spread the love

1. Overview

In this article, we’ll explore the property expansion mechanism provided by Spring through Maven Build method.

2. Configuration

In resource files, we can use ${…} placeholder as variables which are replaced by system or maven properties during build time.

By default, maven resource filtering is not enabled. If we extend our Spring Boot project from spring-boot-starter-parent the resource filtering is enabled by default. In that case, @..@ delimiter is used instead of ${}, that is to avoid conflict with the spring-style placeholder ${}.

If we don’t extend spring-boot-starter-parent  but instead, importspring-boot-dependencies then we have to enable maven resource filtering ourselves.

For Maven projects using the spring-boot-starter-parent, there is no need for extra configurations to make use of property expansions:

	<relativePath/> <!-- lookup parent from repository -->

Now we can expand our project’s properties using @…@ placeholders. Here is an example of how we may save the project’s version taken from Maven, into our properties:

We can only use these expansions within configuration files matching these patterns:

  • **/application*.yml
  • **/application*.yaml
  • **/application*.properties

In the absence of the spring-boot-starter-parent parent, we’ll need to configure this filtering and expansion manually. We’ll need to include resources element into the <build> section of our pom.xml file:


And in the <plugins>:


Now, the mail class will be configured like this

public class PropertyExpansionSpringApplication {

    CustomBean customBean() {
        return new CustomBean();

    public static void main(String[] args) throws InterruptedException {
        SpringApplication bootApp = new SpringApplication(PropertyExpansionSpringApplication.class);
        ConfigurableApplicationContext context =;
        CustomBean customBean = context.getBean(CustomBean.class);

    private static class CustomBean {

        private String projectName;

        private String springVersion;

        private String appTitle;

        public void doSomething() {
            System.out.printf("Project name: %s%n"
                            + "Spring version: %s%n"
                            + "App title: %s%n",
                    projectName, springVersion, appTitle);


Output :

Project name: Spring-Boot-Tutorial
Spring version: 5.1.9.RELEASE
App title: Application Title

3. Conclusion

In this quick tutorial, we saw how to automatically expand Spring Boot properties using Maven

Github Repository

As always, Please find the code in Github: Click Here

Leave a Reply