javaspringspring-bootspring-properties

How to set spring property to a null value from an environment variable


Spring properties can be bound from environment variables: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables

I've tried various forms of null, NULL, #{null} but always end up with failed to convert java.lang.String to java.time.Duration (caused by java.lang.IllegalArgumentException: 'null' is not a valid duration)

How does one set a null value from an environment variable?


Solution

  • You cannot set a null value from an environment variable (or any other property source). This Spring Boot issue is tracking adding support for binding null values.