I had a similar problem and I could solve it using this approach using Spring Boot and Java 8, hope this helps someone:
@Configuration @PropertySources({ @PropertySource("classpath:integration.properties"), @PropertySource(value = "classpath:integration-${spring.profiles.active}.properties", ignoreResourceNotFound = true) }) @ConfigurationProperties(prefix = "integration") public class IntegrationProperties { private String user; private String password; private String projectId; .... }
integration.properties
integration.user=User integration.password=Password integration.project-id=123
integration-prod.properties
integration.project-id=897
Spring Boot will create a bean using the properties file, and for production (using the prod profile) it will use a different file and override the project-id . ignoreResourceNotFound = true will avoid a FileNotFoundException on startup if you are not using a prod profile.
source share