Can I set null as the default value for a @Value in Spring?

前端 未结 5 942
暗喜
暗喜 2020-12-23 02:40

I\'m currently using the @Value Spring 3.1.x annotation like this:

@Value(\"${stuff.value:}\")
private String value;

This puts an empty Str

5条回答
  •  不知归路
    2020-12-23 03:06

    Thanks to @vorburger:

    @Value("${email.protocol:#{null}}")
    String protocol;
    

    will set the string value at null without any other configurations.

提交回复
热议问题