1

I use the solution https://stackoverflow.com/a/42391322/1681932 to activate Spring Boot profile.

It works well in Spring Boot 2.5.0.

Now I want to upgrade to Spring Boot 2.6.6 in my new project. But the solution fails.

application.properties

spring.profiles.active=@spring.profiles.active@

the console show:

The following profiles are active: @spring.profiles.active@

it seems that the notation @spring.profiles.active@ is not replaced, it should be something like dev, prod.


Update:

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.6</version>
        <relativePath/>
    </parent>

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
        </profile>

        <profile>
            <id>prod</id>
            <properties>
                <spring.profiles.active>prod</spring.profiles.active>
            </properties>
        </profile>
    </profiles>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            ...
        </plugins>
    </build>

application.properties

spring.profiles.active=@spring.profiles.active@
## other properties

application-dev.properties

## dev related properties

application-prod.properties

## prod related properties

IDEA output

2022-04-19 19:28:45.377  INFO 8360 --- [           main] c.c.a.MyApplication         : Starting MyApplication using Java 18 on macdeMac-mini.lan with PID 8360 (/Users/mac/proj/MyApplication/target/classes started by mac in /Users/mac/proj/MyApplication)
2022-04-19 19:28:45.381  INFO 8360 --- [           main] c.c.a.MyApplication         : The following 1 profile is active: "@spring.profiles.active@"

If I change 2.6.6 into 2.5.0 in pom.xml, everything works well.

  • 1. Have you created multiple .properties such as `application-dev.properties` ? 2. Could you post your pom.xml ? – Kai-Sheng Yang Apr 19 '22 at 10:37
  • @PeggaPig007 execute from command line the `mvn clean install` and then try to start it again. does this fix the issue? – Panagiotis Bougioukos Apr 19 '22 at 11:51
  • @PanagiotisBougioukos oh thanks, I know the problem. I ran my application using IDEA run/debug button. I need to do `mvn package` before hitting run/debug in IDEA if I have changed maven profile in Maven Panel of IDEA. – PeggaPig007 Apr 19 '22 at 12:30

0 Answers0