Optional Environment Variables with @Value in Spring Boot

时间:2015-09-14 05:34:24

标签: java spring-boot java-8

Using @Value for non-existing environment variable will cause an IllegalArgumentException: Could not resolve placeholder 'ENV_VAR' in string value "${ENV_VAR}".

For example:

@Autowired
public SomeClass(@Value("{ENV_VAR}") final String value) { }

How can I make this value optional?

0 个答案:

没有答案