[Java] SpringBoot 2.3.0 or later fails to resolve the placeholder used in the value of @PropertySource

less than 1 minute read

Content

The title is as it is. In SpringBoot2.3.0 or later, if you use a placeholder like classpath:/something-config-${spring.profiles.active}.yml to specify the value of @PropertySource, exception cannot be resolved. appear. The current latest version of Boot is 2.3.1.

Source

SomethingConfig.java


@Configuration
@ConfigurationProperties(prefix = "something")
@Component
@PropertySource(value = {"classpath:/something-config.yml","classpath:/something-config-${spring.profiles.active}.yml"}, factory = YamlPropertySourceFactory.class)
@Data
public class SomethingConfig {

    private String setting1;
    private String setting2;
}

result

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder'spring.profiles.active' in value "classpath:/somethign-config-${spring.profiles.active}.yml"

Solution

I used 2.2 series for the time being.

issue

https://github.com/spring-projects/spring-boot/issues/21631