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

1

5

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?

Sanferd answered 8/9, 2022 at 8:31 Comment(2)
If you don't specify the variable value, then whether spring takes its value as null ?Trentontrepan
I have a default set in the ConfigurationProperties file. If I don't specify or set MY_VAR to nothing then the default is used.Sanferd
S
7

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.

Stoll answered 8/9, 2022 at 8:46 Comment(3)
It's so pathetic. I need this featureHued
@MaksimEliseev why don't you submit a PR then?Sanferd
@Sanferd That's a good point! My bad :(Hued

© 2022 - 2024 — McMap. All rights reserved.