I'm trying to define the default value as null value in application.yml with SpringBoot version 1.3.0.RELEASE. The goal is be able to refer it with a class with ConfigurationProperties
annotation
-- application.yml --
test.foo: ${test.bar:#{null}}
but it doesn't work.
If the value of test.bar
is not defined, set test.foo
to null (default value)
I already have spring-el in my dependencies. I don't want to use PropertyPlaceholderConfigurer.setNullValue
It's seem to work in @Value
but not in application.yml
(see http://farenda.com/spring/spring-inject-null-value/)
It's a bug, or yaml is not designed for that? I tried all values in http://yaml.org/type/null.html but it doesn't worked either
Thanks
@Value
From the document, we can see:
It is actually three phases here:
AutowiredAnnotationBeanPostProcessor
Environmen
ExpressionParser
User Case
If we define a
test.foo
inapplication.yml
like you have described:Then, we refer to it in code via
@Value
, it works as you said.But If we get it directly from
environment
, it will be plain string:More
So, whether it is work or not depends on how did you use it. I can't provide more help before more info. Hope following related post may help.