@Value("#{systemProperties.configFileLocation}")
private String configFileLocation;
That's all fine and dandy. But what if the property is optional and is not always there? Spring will not like that and will let you know that by throwing:
org.springframework.beans.factory.BeanCreationException: Could not autowire fieldAnd while @Autowire construct provides a required attribute, which can be set to false, alas @Value does not.
This issue is discussed in Captain Debug's Blog where he offers several work-a-rounds to this issue, but all of them seem to be quite cumbersome. So upon digging a little deeper, I stumbled on a Stack Overflow thread where one of the answers suggests following quite simple solution using SpEL Elvis operator:
@Value("#{systemProperties.getProperty('configFileLocation') ?: ''}")
private String configPath;
What this means is that if property exists, its value will be assigned to configPath, if it doesn't exist configPath will be set to blank.