When using Spring Boot Starter Parent 3.5.3 with Maven build profiles, the documented property expansion doesn't work without disabling profile validation.
According to the documentation, to expand properties using a Maven application.yml I should be able to use "@...@"
to reference my Maven property but on trying to build I get an error. Setting spring.profiles.validate=false
resolves the issue but shouldn't be necessary.
Error on start up:
Description:
Failed to bind properties under 'spring.profiles.active' to java.util.Set<java.lang.String>:
Property: spring.profiles.active
Value: "@spring.profiles.active@"
Origin: class path resource [application.yml] - 7:17
Reason: java.lang.IllegalStateException: Profile '@spring.profiles.active@' must start and end with a letter or digit
Link to example project with the issue: property-expansion
Comment From: snicoll
@meganjohn thanks for the report and the sample. I've tried your sample and I don't really see how I can make it fail the way you've described. ./mvnw spring-boot:run
starts the app for me. I noticed a dev
profile so I tried ./mvnw -Pdev spring-boot:run
and that worked too. Can you please clarify?
Comment From: LiamMacP
@snicoll @meganjohn is within my team but on leave now so unable to respond.
To reproduce I have pulled the example project and run the following: ./mvnw clean install -Pdev
.
This has thrown out the error that Megan has pointed out.
It specifically seems to be around the running of tests that are annotated with @SpringBootTest
with it being unable to load the context with error: Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.profiles.active' to java.util.Set<java.lang.String>
.
More specifically going down the stacktrace it throws the following: Caused by: java.lang.IllegalStateException: Profile '@spring.profiles.active@' must start and end with a letter or digit
.
Let me know if I could be of further assistance.
Comment From: snicoll
Thanks, "error on start up" made me think the error occurred when the app is starting.
Now that we've confirmed the problem only occurs with the dev
profile I can focus on that. This profile declares a resource
element, effectively replacing the configuration from the parent that enables the filtering.
I've changed the dev
profile to be as follows and that fixed the issue:
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
As for the error, there are some restrictions for profiles and the value token is an invalid profile name. That's probably for the best as you don't want to start an app that hasn't the profile token resolved.