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.