0
votes

I am following this tutorial so that Maven will replace values in my application.properties file depending on the build profile:

https://www.petrikainulainen.net/programming/tips-and-tricks/creating-profile-specific-configuration-files-with-maven/

  1. It states to put some config files under the "profiles" directory. Where is this directory? I created a folder named "profiles" in the root of the project directory.

  2. How do I activate a profile? I Googled around and I added -P to the commands, for example "mvn test" would be "mvn test -P staging"

Needless to say, it is not working. Even when the default profile "dev" is supposed to be activated without any action necessary, my application.properties file is not affected.

1
Saying it clearly the tutorial is simply wrong. A spring-boot profile is something different than a maven profile. Having different profiles in spring-boot can be achieved by using application-dev.properties whereas the application.properties is the default. You can have as many as you wish. Those spring boot profiles can be activated via --spring.profiles.active=dev for example. No directories needed etc. - khmarbaise
Please read the documentation of Spring boot about profiles for example springboottutorial.com/spring-boot-profiles and take look at docs.spring.io/spring-boot/docs/current/reference/html - khmarbaise

1 Answers

-1
votes

The tutorial I linked above worked. The only difference is that when using for Spring Boot with the spring-boot-starter-parent

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

The format of the placeholder string is

and not

${my.variable}