I have set the Environment variable JAVA_OPTS (-Dappconfig=D:/cc/dd -Dfarm=test and want to read properties from a property using the following code but no matter what I tried I got the error below. I need to do this for different environments (test, staging,dev , prod). Any help is appreciated
Caused by:
java.lang.IllegalArgumentException: Could not resolve placeholder 'appconfig' in string value
"file:${appconfig}/farm/${farm}/myservice.appconfig.properties"
@Configuration
@PropertySource(value = "file:${appconfig}/farm/${farm}/myservice.appconfig.properties", ignoreResourceNotFound = false)
public class AppConfig
{
@Autowired
private Environment environment;
@Bean
public AppConfigSettings getAppConfig()
{
AppConfigSettings properties = new AppConfigSettings()
//I set properties using environment.getRequiredProperty("propertykey") //here
return properties;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
{
return new PropertySourcesPlaceholderConfigurer();
}
}