I am working on an Spring web application in where I need to have variable\'s that will have different value in local environment and other value in production environment.<
In my case above any solutions didn't work so I did some google from my end and finally found some working solution for it.
I've modified the above class as follows:
@Configuration
@PropertySource("classpath:application-${spring.profiles.active}.properties")
public class MyApplicationConfiguration {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
return configurer;
}
}
Instead of defining dynamic file name inside the method. I am defining the file name as below which does the magic for me.
@PropertySource("classpath:application-${spring.profiles.active}.properties")
at the top of the class. By following Bart's solution I was not getting any errors but I was getting all the properties to value null defined inside property files.
by using my approach spring is able to recognize properties defined in VM arguments and in environment variable both. Note: I am using a non-spring boot project.