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

前端 未结 5 917
暗喜
暗喜 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:04

    In case you need to inject an empty (0 length) "" string as @Value default - use SPEL (spring expression language) as follows:

    @Value("${index.suffix:#{''}}") 
    private String indexSuffix;
    

    #{''} just gets you an empty string as injected @Value's default.

    by yl

提交回复
热议问题