Spring

Problem: To allow null in @value or to set null as default in Spring @value annotation if the property does not exist.

Solution: after property include :#{null}

Example:

// Non null allowed value
@Value("${property.value}")
String propertyName

// Nullable and null as default value
@Value("${property.value:#{null}}")
String propertyName

Explanation: Here we are using Spring Expression Language (SpEL) to set null as default value if does not exist in properties.

Source: documentation

For more interesting tutorials & guides just check them HERE.

Leave a Reply

Your email address will not be published. Required fields are marked *