79726003

Date: 2025-08-05 10:58:20
Score: 0.5
Natty:
Report link

If you can treat blank values as missing, and can use SpEL and the Elvis operator

@Value("#{'${some.value:}' ?: null}")
private String someValue;

This works because a missing some.value will lead to an empty string which is "falsy" and then the elvis operator goes with the fallback. In the SpEL expression - so in the #{...} scope - null means null and not the string "null".

As compared to @EpicPandaForce's answer:

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @EpicPandaForce's
  • Low reputation (0.5):
Posted by: Anly