adding new property based on spring profile

fortm :

If spring boot is run in override profile , can we have application-override.properties having properties like foo.baz that is not defined in application.properties ?

application.properties

foo.bar=1

application-override.properties

spring.profiles.include=default 
foo.baz=1
Jakubeeee :

You can create configuration class for your custom profile and load the appropriate properties file in it like this:

@Configuration
@Profile("override")
@PropertySource("classpath:application-override.properties")
public class OverrideConfig {

}

This way, all the configuration you do in OverrideConfig (including taking properties from application-override.properties), will only load if override profile is enabled in application.properties like this:

spring.profiles.active=override

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=112682&siteId=1